Android开发读取assert下的txt文件
2015-09-28 15:43
429 查看
在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);
相关文章推荐
- Android studio 怎么设置Live Template
- 【Android】Spinner使用
- android中的栈,Task
- android的性能优化和应用体验改善
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
- 利用gdb 调试android jni c动态库
- ImageView的属性android:scaleType
- Android_Studio常用插件
- Android学习笔记-junit测试
- Android中弹出对话框,AlertDialog关键代码
- Android中万能适配器
- 关于android中调用系统拍照,返回图片是旋转90度...
- android项目之间的相互引用出现的问题
- Android应用方法数查看,查看size是否超过65k
- Android View研究
- Android Android Studio 快捷键整理分享,IntelliJ IDEA使用技巧一览表
- Android事件处理机制研究
- Android ListView 适配键值事件和点击事件
- Android Layout Xml的命名空间
- Android内存泄漏之 handler