转自文章 http://www.linuxidc.com/Linux/2012-11/74781.htm
http://www.2cto.com/kf/201306/223572.html
获取Android设备的外存路径的接口为:
- Environment.getExternalStorageDirectory().getAbsolutePath()
所以,给自己的程序建个目录可如下所写:
- String appHome = Environment.getExternalStorageDirectory().getAbsolutePath()+"/myApp";
- createDir(appHome)
但是,如果要建多层目录的文件夹的话,可不能一蹴而就。像下面这样写代码的话,执行代码后,在Android设备的外存里是不会创建文件夹“myApp/sub”的:
- String appHome = Environment.getExternalStorageDirectory().getAbsolutePath()+"/myApp";
- createDir(appHome)
如果要建多层目录的文件夹,只能是一步一步的建,如下所示:
- String appHome = Environment.getExternalStorageDirectory().getAbsolutePath()+"/myApp";
- String subPath = appHome+"/sub";
- createDir(appHome);
- createDir(subPath);
Android不同api调用显示的路径:
[java]
Environment.getExternalStorageState:mounted
Environment.getDownloadCacheDirectory().getPath():/cache
Environment.getDataDirectory().getPath():/data
Environment.getExternalStorageDirectory().getPath():/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getPath():/mnt/sdcard/Pictures
Environment.getRootDirectory().getPath():/system
Environment.getDownloadCacheDirectory().getAbsolutePath():/cache
Environment.getDataDirectory().getAbsolutePath():/data
Environment.getExternalStorageDirectory().getAbsolutePath():/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getAbsolutePath():/mnt/sdcard/Pictures
Environment.getRootDirectory().getAbsolutePath():/system
Environment.getExternalStorageState:mounted
Environment.getDownloadCacheDirectory().getPath():/cache
Environment.getDataDirectory().getPath():/data
Environment.getExternalStorageDirectory().getPath():/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getPath():/mnt/sdcard/Pictures
Environment.getRootDirectory().getPath():/system
Environment.getDownloadCacheDirectory().getAbsolutePath():/cache
Environment.getDataDirectory().getAbsolutePath():/data
Environment.getExternalStorageDirectory().getAbsolutePath():/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getAbsolutePath():/mnt/sdcard/Pictures
Environment.getRootDirectory().getAbsolutePath():/system