猿问

Android在内部存储器中创建文件夹

有什么方法/可以在Android的内部存储器中创建文件夹吗?范例:


- data

-- com.test.app (application's main package)

---databases (database files)

---files (private files for application)

---shared_prefs (shared preferences)


---users (folder which I want to create)

users例如,我可以在内部存储器中创建文件夹吗?


ibeautiful
浏览 1873回答 3
3回答

ITMISS

我用它在内部存储器中创建文件夹/文件:File mydir = context.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;File fileWithinMyDir = new File(mydir, "myfile"); //Getting a file within the dir.FileOutputStream out = new FileOutputStream(fileWithinMyDir); //Use the stream as usual to write into the file.

拉丁的传说

context.getDir(“ mydir”,...); 这将创建your.package / app_mydir /&nbsp;/** Retrieve or creates <b>path</b>structure inside in your /data/data/you.app.package/&nbsp;* @param path "dir1/dir2/dir3"&nbsp;* @return&nbsp;*/private File getChildrenFolder(String path) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File dir = context.getFilesDir();&nbsp; &nbsp; List<String> dirs = new ArrayList<String>(Arrays.<String>asList(path.split("/")));&nbsp; &nbsp; for(int i = 0; i < dirs.size(); ++i) {&nbsp; &nbsp; &nbsp; &nbsp; dir = new File(dir, dirs.get(i)); //Getting a file within the dir.&nbsp; &nbsp; &nbsp; &nbsp; if(!dir.exists()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dir.mkdir();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return dir;}
随时随地看视频慕课网APP

相关分类

Android
我要回答