当前位置: 编程技术>移动开发
android读取assets文件示例
来源: 互联网 发布时间:2014-10-23
本文导语: 代码如下:// 读取assets文件private void assetsRead(){String fileName = "my_assets.txt";// assets下文件//String fileName = "test/my_assets_test.txt";// assets下子目录文件String ret = "";try {InputStream is = getResources().getAssets().open(fileName);int len = is.available();byte []...
代码如下:
// 读取assets文件
private void assetsRead(){
String fileName = "my_assets.txt";// assets下文件
//String fileName = "test/my_assets_test.txt";// assets下子目录文件
String ret = "";
try {
InputStream is = getResources().getAssets().open(fileName);
int len = is.available();
byte []buffer = new byte[len];
is.read(buffer);
ret = EncodingUtils.getString(buffer, "utf-8");
is.close();
} catch (Exception e) {
e.printStackTrace();
}
tvTXT.setText(ret);
}