简体   繁体   中英

creating folder in android emulator

I am developing an android application. I need to create a folder in the internal memory, but when I try to create the folder I get the error below. I am running in an emulator.

 mkdir failed for /mnt/New Folder , read only file system

I have tried many paths, but still the error persists. The only folder that I am able to create is called "cache", but I cannot browse it by my file chooser activity. Any idea where is the suitable place to create folders without any permissions?

You can achieve it by this from a Context object (like Activity).

File files_folder = getFilesDir(); 
File files_child = new File(files_folder, "files_child"); 
files_child.mkdirs(); 
File created_folder = getDir("custom", MODE_PRIVATE); 
File f1_child = new File(created_folder, "custom_child"); 
f1_child.mkdirs(); 

The function

getFilesDir()

will get the folder data/data/yourpackagename/files in internal memory. And the function

getDir("custom", MODE_PRIVATE)

will create a folder name app_custom in your app internal folder.

Answered by Minhtdh

I guess what you call internal memory is atualy the external memory (which can be open by

file chooser activity, the real internal memory only can be open if you have rooted)

If that true, you should chek those belows: - first, you will need the write storeage permission in Manisfest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> - then you should use `

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/yourfoldername"

` than

mnt/yourfoldername

  • at last you should use mkdirs to create folder than mkdir

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM