如何在Android data/data/project文件系统中创建文件目录和文件夹
我正在开发一个视频编辑器程序,并且对 android 和 java 相当陌生。我希望发生的是,当用户按下“创建新项目”按钮时,会弹出一个对话框,询问用户项目的名称。我已经把那部分写下来了,但是我想要的是,当用户在该对话框上按“确定”时,我的代码将采用该名称并在我的项目的数据/数据文件内创建一个目录,并在该目录内创建一个目录标题为 1 到 5 或更多的文件夹。我真的不知道该怎么做,所以任何意见都会非常感激。
I am working on a video editor program and am fairly new to android and java. What I would like to happen is when the user presses "create new project" button, a dialog pops up asking the user for the name of the project. I have that part down, but what I then want, is when the user presses "ok" on that dialog, my code will take the name and create a directory inside of my data/data file for my project and inside of that directory create folders titled 1 to 5 or more. I really don't know how to go about this, so any input would be truly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
正如 sgarman 提议的那样,您可以使用 SD 卡(我认为它更好),但如果您想使用应用程序目录,您可以通过从 Activity 中调用
getFilesDir()
来获取它,它将返回 </data/data/your.app/files
的 code>File 对象,然后您可以获得路径并附加新目录:As sgarman proposed you can use the SD card (and I think it's better) but if you want to use your application dir you can get it by calling
getFilesDir()
from your activity, it will return aFile
object of/data/data/your.app/files
then you can get the path and append the new directory:对于主要设备所有者来说,获取驻留在外部存储上的 Android/data/packagename 下的目录的正确方法是在可用的上下文上调用 getExternalFilesDir() 。
也就是说,
你还必须在 Manifest 中添加写权限
The proper way to get a directory that, for the primary device owner, resides under Android/data/packagename on external storage, is just to call getExternalFilesDir() on an available Context.
That is,
And also you have to add write permission in Manifest
查看 getFilesDir 方法,该方法将返回您正在寻找的目录。您可能还想创建一个子目录。
Check out the getFilesDir method which will return the directory you're looking for. You'll probably want to make a subdirectory as well.
您必须尝试在 Android/data/data/your.app/ 中创建文件夹。
在您的
onCreate
方法中使用它。You must try this to create folder in Android/data/data/your.app/.
use this in your
onCreate
method.这个方法在我的应用程序中有效。我使用上面讨论的所有方法都不起作用
File file= new File(Environment.getExternalStorageDirectory().toString()+"/Android/data/com.package_name/your_folder_name")
此方法用于在应用程序的数据目录中创建文件夹此文件夹图像和视频无法在图库中访问,但可以使用文件夹路径手动访问应用程序中的所有文件
This method work in my App. I use all method above discuss here not working
File file= new File(Environment.getExternalStorageDirectory().toString()+"/Android/data/com.package_name/your_folder_name")
this method used to create folder in data Directory of Your App This folder images and video not access in Gallery but manually access all files in your app use of folder path