在内部存储的android创建目录 [英] Creating directory in internal storage android

查看:345
本文介绍了在内部存储的android创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在目录中创建目录。要创建一个目录只需拨打这样的:

Is it possible to create directory in directory. To create one directory simply call this:

File dir1 = getDir("dir1",Context.MODE_PRIVATE);

但如何在 DIR1 其他目录?

这样的:

File dir2 =getDir("dir1"+"/"+"dir2",Context.MODE_PRIVATE);

抛出异常:

File dirFile = java.lang.IllegalArgumentException: File app_dir1/dir2 contains a path separator

感谢。

推荐答案

在Context.getDir()似乎是抽象出来的​​专用存储区中创建一个目录的过程中Android的独特的方法 - 它不是一个一般制作目录的通用方法。

The Context.getDir() appears to be an Android-unique method for abstracting out the process of creating a directory within the private storage area - it is not a generic way of making directories in general.

为了让您的孩子子目录,你应该使用一般的Java方法,如

To make your child subdirectory, you should use normal java methods, such as

File dir2 =new File(dir1, "dir2").mkdir();

请注意,第一个参数这里是文件对象重新presenting你创建的第一个目录,而不是名字。

Note that the first parameter here is the File Object representing the first directory you created, not the name.

您可能希望以后设置权限,这个目录。

You may want to subsequently set the permissions on this directory.

警告:未经测试

这篇关于在内部存储的android创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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