无法创建 nomedia 文件
通过Android SDK和AVD Manager我创建了一个android3.0版本的AVD,大小选项为1024MiB。在我的应用程序类中,我要求创建一个目录,以便可以缓存图像。但我在那里遇到错误,因为
09-07 15:32:31.253: ERROR/AndroidRuntime(380): Caused by: java.lang.IllegalStateException: Unable to create nomedia file.
我的代码是:
File baseDirectory = new File(Environment.getExternalStorageDirectory(), "myapp");
File storageDirectory = new File(baseDirectory, "imagecache");
File nomediaFile = new File(storageDirectory, NOMEDIA);
nomediaFile.createNewFile();
错误出现在第四行。有人可以帮我吗?我是蜂窝新手。提前致谢。
Through Android SDK and AVD Manager I have created an AVD of android3.0 version with size option as 1024MiB. In my application class I have asked to create a directory so that I can cache images. But I get error over there as
09-07 15:32:31.253: ERROR/AndroidRuntime(380): Caused by: java.lang.IllegalStateException: Unable to create nomedia file.
My code is:
File baseDirectory = new File(Environment.getExternalStorageDirectory(), "myapp");
File storageDirectory = new File(baseDirectory, "imagecache");
File nomediaFile = new File(storageDirectory, NOMEDIA);
nomediaFile.createNewFile();
Error comes over in the 4th line. Could anyone please help me out. I am new to honeycomb. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如其他人所建议的,您应该使用
mkdirs()
来确保您的目录路径在那里。您还需要WRITE_EXTERNAL_STORAGE
权限。As others have suggested, you should have
mkdirs()
to ensure your directory path is there. You also need theWRITE_EXTERNAL_STORAGE
permission.