读写内部文件
来源:互联网 发布:程序员出差注意事项 编辑:程序博客网 时间:2024/05/14 06:18
public class MainActivityextends ActionBarActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
findViewById(R.id.button_write).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
FileOutputStream fileOutputStream = openFileOutput("myfile.txt", Context.MODE_PRIVATE);
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "utf-8");
outputStreamWriter.write("烂州是全国最不适合经商创业的省会城市\n建议把全国各地的左派集中在甘肃居住\n甘肃只适合计划经济");
outputStreamWriter.flush();
outputStreamWriter.close();
fileOutputStream.close();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
findViewById(R.id.button_read).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
FileInputStream inputStream = openFileInput("myfile.txt");
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
char buffer[] =new char[inputStream.available()];
inputStreamReader.read(buffer);
inputStreamReader.close();
inputStream.close();
String str = new String(buffer);
textView.setText(str);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
- 内部存储空间读写文件
- 读写内部文件
- 内部存储读写文件
- Hadoop读写文件时内部工作机制
- Hadoop读写文件时内部工作机制
- 读写内部存储的文件数据
- Android中外部,内部文件读写
- 读写内部存储的文件数据
- Android 内部存储中读写文件
- android内部存储读写文件详解
- 6.读写内部存储的文件
- Hadoop读写文件时内部工作机制
- Android 内部存储文件读写权限
- 读写内部存储的文件数openFileOutput(),openFileInput()
- Hadoop读写文件时内部工作机制是怎样的?
- 【eclipse rcp开发】插件内部文件读写方法
- 数据存储—读写内部存储的文件数据
- Android -- 读写文件到内部ROM,SD卡,SharedPreferences,文件读写权限
- 自定义Spinner
- java内存泄露场景及解决方案
- Android手机实时视频监控
- CoreLocation、MapKit和地理围栏1
- web app变革之rem
- 读写内部文件
- 应用层直接操作gpio口及出现的问题sh: write error: Device or resource busy
- Android 6.0 使用 Apache HttpClient
- ACM 中wrong answer(WA)的一种处理办法 UVA10474 where is the marble
- 不能滑动的ViewPager
- Codeforces 631C Report 【单调栈】
- Frontend maven plugin
- Oracle Net Manager 服务命名配置原理,方法,用途
- 1 Javascript:交互式网络