3

I'm developing a simple application for Android devices.

I need to create a directory, but I can't do it.

File folder = new File(Environment.getExternalStorageDirectory ()+"/dir");

if(folder.mkdirs()){
   CrearToast("Directorio creado"); //successfully created
}else{
   CrearToast("fallo"); // error creating directory
}

*CrearToast creates a toast with the text in brackets.

I have set uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

Kanttarino
  • 57
  • 1
  • 7
  • Are you sure the directory is not already created, it sounds like http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html#mkdirs() will return false if they did not need to make the dirs directory. – sgarman Aug 13 '11 at 23:41

1 Answers1

5

are you trying to write on SD card or phone memory?? Have you looked at this?? http://developer.android.com/guide/topics/data/data-storage.html

EDIT: This is how i create my folders

File CheckDirectory;
CheckDirectory = new File(FolderPath);
if (!CheckDirectory.exists()){ 
CheckDirectory.mkdir();
}

SD card directory:

Environment.getExternalStorageDirectory().getAbsolutePath() + "/";

jsp
  • 2,546
  • 5
  • 36
  • 63