Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. //从raw对资源文件进行数据的读取
  2. public byte[] getBytes() {
  3. try (InputStream in = getResources().openRawResource(R.raw.cadaman);) {
  4. int length = in.available();
  5. byte[] buffer = new byte[length];
  6. in.read(buffer);
  7. return buffer;
  8. } catch (Exception ex) {
  9. return null;
  10. }
  11. }
  12.  
  13. public String getString() {
  14. try (InputStream in = getResources().openRawResource(R.raw.cadaman);) {
  15. int length = in.available();//获取文件的大小(字节数)
  16. byte[] buffer = new byte[length];//创建一个byte数组, 用于装载字节信息
  17. in.read(buffer);//开始读取文件,将读取到的字节放入到buffer这个数组中
  18. String temp = null;
  19. temp = EncodingUtils.getString(buffer, "UTF-8");
  20. //temp = EncodingUtils.getString(buffer, "UNICODE");
  21. //temp = EncodingUtils.getString(buffer, "BIG5");
  22. //temp = EncodingUtils.getString(buffer, "ANST");
  23. //String temp = new String(buffer);
  24. return temp;
  25. } catch (Exception ex) {
  26. return null;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement