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