如何在Android数据/数据/项目文件系统中创建文件目录和文件夹 [英] How to create file directories and folders in Android data/data/project filesystem

查看:580
本文介绍了如何在Android数据/数据/项目文件系统中创建文件目录和文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个视频编辑器程序,对于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.

推荐答案

由于sgarman提出你可以使用SD卡(我认为更好),但是如果要使用您的应用程序目录,您可以通过从活动中调用 getFilesDir()获取它,它将返回文件对象 /data/data/your.app/files 然后你可以获得路径并附加新的目录:

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 a File object of /data/data/your.app/files then you can get the path and append the new directory:

String dirPath = getFilesDir().getAbsolutePath() + File.separator + "newfoldername";
File projDir = new File(dirPath);
if (!projDir.exists())
    projDir.mkdirs();
...

这篇关于如何在Android数据/数据/项目文件系统中创建文件目录和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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