在Android工程的assert根目录下存在txt文件test.txt文件,读取内容的办法如下:
String content = "加载错误";
try
{
InputStream is = getAssets().open("test.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
content = new String(buffer, "GB2312");
} catch (Exception e)
{
}
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(content);
String content = "加载错误";
try
{
InputStream is = getAssets().open("test.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
content = new String(buffer, "GB2312");
} catch (Exception e)
{
}
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(content);