android读取assets文件示例
程序员文章站
2023-10-28 20:27:04
复制代码 代码如下:// 读取assets文件private void assetsread(){string filename = "my_assets.txt";//...
复制代码 代码如下:
// 读取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);
}