文件输出流--存储进去
FileOutputStream fos= null;
fos = context.openFileOutput(filename, Context.MODE_PRIVATE);fos.write(filecontent.getBytes("UTF-8"));
fos.close();
默认位置 /data/data/package/file
文件输入流-提取数据
FileInputStream in = null;
ByteArrayOutputStream bout = null;
byte[]buf = new byte[1024];
bout = new ByteArrayOutputStream();
int length = 0;
//得到输入流
in = context.openFileInput(filename);
while((length=in.read(buf))!=-1){
bout.write(buf,0,length);
}
byte[] content = bout.toByteArray();
//设置文本框为读取内容
filecontentEt.setText(new String(content,"UTF-8"));
in.close();
bout.close();
本文深入探讨了Android中文件输出流(FileOutputStream)和文件输入流(FileInputStream)的使用方法,包括如何将文件内容写入指定路径及从文件中读取数据,并通过实例演示了操作流程。
1371

被折叠的 条评论
为什么被折叠?



