Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //从raw对资源文件进行数据的读取
- public byte[] getBytes() {
- try (InputStream in = getResources().openRawResource(R.raw.cadaman);) {
- int length = in.available();
- byte[] buffer = new byte[length];
- in.read(buffer);
- return buffer;
- } catch (Exception ex) {
- return null;
- }
- }
- public String getString() {
- try (InputStream in = getResources().openRawResource(R.raw.cadaman);) {
- int length = in.available();//获取文件的大小(字节数)
- byte[] buffer = new byte[length];//创建一个byte数组, 用于装载字节信息
- in.read(buffer);//开始读取文件,将读取到的字节放入到buffer这个数组中
- String temp = null;
- temp = EncodingUtils.getString(buffer, "UTF-8");
- //temp = EncodingUtils.getString(buffer, "UNICODE");
- //temp = EncodingUtils.getString(buffer, "BIG5");
- //temp = EncodingUtils.getString(buffer, "ANST");
- //String temp = new String(buffer);
- return temp;
- } catch (Exception ex) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement