获取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);