Created
December 3, 2014 09:20
-
-
Save einverne/e5c63948a7eec33f2084 to your computer and use it in GitHub Desktop.
get file content from Android assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//从assets 文件夹中获取文件并读取数据 | |
public String getFromAssets(String fileName) { | |
String result = ""; | |
try { | |
InputStream in = getResources().getAssets().open(fileName); | |
// 获取文件的字节数 | |
int lenght = in.available(); | |
// 创建byte数组 | |
byte[] buffer = new byte[lenght]; | |
// 将文件中的数据读到byte数组中 | |
in.read(buffer); | |
result = EncodingUtils.getString(buffer, "UTF-8"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment