Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public String getString() {
  2. try (InputStream in = getResources().getAssets().open("hello.txt");) {
  3. int length = in.available();//获取文件的大小(字节数)
  4. byte[] buffer = new byte[length];//创建一个byte数组, 用于装载字节信息
  5. in.read(buffer);//开始读取文件,将读取到的字节放入到buffer这个数组中
  6. String temp = null;
  7. temp = EncodingUtils.getString(buffer, "UTF-8");
  8. //temp = EncodingUtils.getString(buffer, "UNICODE");
  9. //temp = EncodingUtils.getString(buffer, "BIG5");
  10. //temp = EncodingUtils.getString(buffer, "ANST");
  11. //String temp = new String(buffer);
  12. return temp;
  13. } catch (Exception ex) {
  14. return null;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement