在应用程序目录中创建文件夹 [英] Creating folder in the application directory

查看:70
本文介绍了在应用程序目录中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用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.

推荐答案

使用方法

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.

这篇关于在应用程序目录中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆