Skip to content

Instantly share code, notes, and snippets.

@einverne
Created December 3, 2014 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einverne/e5c63948a7eec33f2084 to your computer and use it in GitHub Desktop.
Save einverne/e5c63948a7eec33f2084 to your computer and use it in GitHub Desktop.
get file content from Android assets
//从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