我已经使用getFilesDir()在应用程序目录中创建一个文件夹,它给出了applicatoin目录的路径,如下所示
i have used getFilesDir() to create a folder in the application directory, it gives the path of the applicatoin directory as follows
/data/data/{我的应用程序包}/文件
/data/data/{my application package}/files
但是当我使用它使用
File folder = new File(getFilesDir() + "/MyFolder"); if (!folder.exists()) { folder.mkdir(); }我没有看到任何文件夹.另外,当我在 ES Explorer 中访问时,应用程序目录的实际路径为
i don't see any folder. Also when i access in ES Explorer the actual path of the application directory is
/Android/data/{我的软件包名称}/文件
/Android/data/{my package name}/files
我的问题是如何在应用程序目录中创建一个文件夹,以便在卸载应用程序时可以将其自动删除.
My question is how to create a folder in the application directory so that it can be deleted automatically on application uninstallation.
推荐答案使用方法 Context.getDir() 代替.您不需要调用mkdirs(),因为getDir()会自动执行.
Use method Context.getDir() instead. You don't need to invoke mkdirs(), because getDir() will do it automatically.
文档引用:
检索,如果需要,创建一个新目录,应用程序将在该目录中 可以放置自己的自定义数据文件.您可以使用返回的文件 对象来创建和访问此目录中的文件.注意文件 通过File对象创建的文件只能由您自己访问 应用;您只能设置整个目录的模式,而不能设置 单个文件.
Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.
更多推荐
在应用程序目录中创建文件夹
发布评论