SShehab
SShehab

Reputation: 1051

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?

Upvotes: 2

Views: 4304

Answers (2)

Noman Arain
Noman Arain

Reputation: 1162

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

Upvotes: 1

justHooman
justHooman

Reputation: 3054

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

Upvotes: 0

Related Questions