如何建立在Android内部存储的文件? [英] How to create a file on Android Internal Storage?
本文介绍了如何建立在Android内部存储的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在内部存储的文件保存到特定的文件夹。我的code是:
I want to save a file on internal storage into a specific folder. My code is:
File mediaDir = new File("media");
if (!mediaDir.exists()){
mediaDir.createNewFile();
mediaDir.mkdir();
}
File f = new File(getLocalPath());
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
fos.write(data);
fos.close();
getLocalPath
返回 /data/data/myPackage/files/media/qmhUZU.jpg
但是当我想创建介质文件夹中,我发现了异常java.io.IOException异常:只读文件系统。任何想法怎么写我的手机内部存储的文件在文件夹中的媒体?谢谢你。
getLocalPath
returns /data/data/myPackage/files/media/qmhUZU.jpg
but when I want to create the media folder I'm getting the exception "java.io.IOException: Read-only file system". Any ideas how to write my files on internal phone storage in in folder media? Thanks.
推荐答案
您应该使用 ContextWrapper 是这样的:
ContextWrapper cw = new ContextWrapper(context);
File directory = cw.getDir("media", Context.MODE_PRIVATE);
与往常一样,参阅文档,的 ContextWrapper 有很多提供。
这篇关于如何建立在Android内部存储的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文