android——写文件到手机上
2023-04-12
写文件到手机与写文件到sd卡的一个很大的区别就在于:前者将文件写到
/data/data目录下的该程序的目录下(第一次写的时候,系统会自动帮你新建一个名为files的目录),
而后者则会将文件写到/mnt/sdcard目录下。两者存储位置的差别如下图所示:
1、sd卡的存储目录

2、文件在手机中的存储目录:

实现
1、FileService
在写文件到sd卡的基础上加上以下代码:
private Context context;
public FileService(Context context) {
this.context = context;
}
public void saveToRom(String name, String content) throws Exception {
FileOutputStream fos = context.openFileOutput(name, Context.MODE_PRIVATE);
fos.write(content.getBytes());
fos.close();
}
2、ManActivity
将new FileService()-------------------->>new FileService(this);
本文仅代表作者观点,版权归原创者所有,如需转载请在文中注明来源及作者名字。
免责声明:本文系转载编辑文章,仅作分享之用。如分享内容、图片侵犯到您的版权或非授权发布,请及时与我们联系进行审核处理或删除,您可以发送材料至邮箱:service@tojoy.com



