2 momo1199 Momo1199 于 2013.03.14 16:41 提问

android中创建应用文件夹

本人要在onCreate()方法的第一个activity中创建应用文件夹,但是没创建成。代码如下:

 if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
        File fil = new File(this.getFilesDir().getPath()+File.separator+"MyContactsBackUp");
        fil.mkdirs();

} else {
    File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"MyContactsBackUp");
    directory.mkdirs();
}

3个回答

Kakalapa1986
Kakalapa1986   2013.03.15 10:00
已采纳
File f = new File(android.os.Environment.getExternalStorageDirectory(),File.separator+"MyContactsBackUp/");
f.mkdirs();

如果是内部核心应用:

File f = new File(getCacheDir(),File.separator+"MyContactsBackUp/");
f.mkdirs();
dianqiugg
dianqiugg   2013.03.16 10:31

有没有加权限:

<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- 在sdcard中创建/删除文件的权限 -->
<uses-permission
    android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
xinyoulingxi1_tong
xinyoulingxi1_tong   2013.03.14 17:08

代码:

if (android.os.Environment.getExternalStorageState().equals(
    android.os.Environment.MEDIA_MOUNTED)) {

       File podcastFolder = new File(Environment.getExternalStorageDirectory() + File.separator
                                             + getString(R.string.app_name));
} else {
            /* save the folder in internal memory of phone */

    File podcastFolder = new File("/data/data/" + getPackageName()
                    + File.separator + getString(R.string.app_name));

}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!