写:
FlleOutputStream fos=openFlieOutput(fliename,Context.MODE_PRIVATE);
包装OutputStreamWriter osw=new OutputStreamWriter(fos,"UTF_8");可以直接向文件中写入字符串数据
osw.write(et.getText().toString());
osw.flush();
fos.flush();//保证输出所有缓冲区当中的内容
osw.close();
fos.close();//后打开的流先关闭
读:
FlieInputStream fis= openFileInput(fliename);//直接读取程序文件内容
InputStreamReader is=new InputStreamReader(fis,"UTF-8");//将字节流包装成字符流
char input[]=new char[fis.available()];//构建字符数组
is.read(input);
is.close();
fis.close();
String readed=new String(input);
show.setText(readed);
在文件的读写过程中,容易出现io错误,所有需要捕获