内部存储文件即raw和assets项目文件夹下的文件,项目卸载时被删除。
四种文件 *** 作模式
文件存储:
public voID save(String filename, String filecontent) throws Exception {
//这里我们使用私有模式,创建出来的文件只能被本应用访问,还会覆盖原文件
fileOutputStream output = mContext.openfileOutput(filename, Context.MODE_PRIVATE);
output.write(filecontent.getBytes()); //将String字符串以字节流的形式写入到输出流中
output.close(); //关闭输出流
}
文件读取:
public String read(String filename) throws IOException {
//打开文件输入流
fileinputStream input = mContext.openfileinput(filename);
byte[] temp = new byte[1024];
StringBuilder sb = new StringBuilder("");
int len = 0;
//读取文件内容:
while ((len = input.read(temp)) > 0) {
sb.append(new String(temp, 0, len));
}
//关闭输入流
input.close();
return sb.toString();
}
总结
以上是内存溢出为你收集整理的Android_内部存储文件的读写全部内容,希望文章能够帮你解决Android_内部存储文件的读写所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)