[英]Android - save file to Device's “data” folder
I need to save some files in the device's "data" folder, because some other application needs them. 我需要将一些文件保存在设备的“数据”文件夹中,因为其他一些应用程序也需要它们。
I've tried 我试过了
new File("/data/filename").createNewFile();
but I get 但我明白了
java.io.IOException: open failed: ENOENT (No such file or directory)
Is the path I'm using wrong? 我使用的路径错误吗?
Try this: 尝试这个:
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("filename", Context.MODE_PRIVATE);
File file = new File("/data/filename");
file.mkdirs();
File mFile = new File(file, filename);
try this 尝试这个
Are you talking about the data folder in root? 您是在谈论根目录下的数据文件夹吗? Then the device must be rooted and you need root permission.
然后,该设备必须是root用户,并且您需要root用户权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.