Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getString() {
- try (InputStream in = getResources().getAssets().open("hello.txt");) {
- 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