在应用程序目录中创建文件夹

编程入门 行业动态 更新时间:2024-10-26 10:35:48
本文介绍了在应用程序目录中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

在应用程序目录中创建文件夹

本文发布于:2023-11-11 21:22:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   文件夹   目录中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!