0

with the below code

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

I have created folder into storage/sdcard/. But I want to create the same folder "ordinazioni" in internal storage.

Mel
  • 5,837
  • 10
  • 37
  • 42
alex
  • 1
  • 4

2 Answers2

0

Your code creates a directory on external storage. Though, it would be much better to use:

File f = new File(Environment.getExternalStorageDirectory(), "ordinazioni");

If you want to create a directory on internal storage, replace Environment.getExternalStorageDirectory() in the above code snippet with a location for internal storage, such as getFilesDir() or getCacheDir() called on a Context (e.g., called on an Activity or Service).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Your code is well but its only the String of in path variable. So with this same path String we will create a Folder or Directory: Lets Do it here :

// Your code 
String path = Environment.getExternalStorageDirectory()
                         .getAbsolutePath() + "/ordinazioni";
// After this
file=new File(path);
if(!file.isDirectory())
{    
    file.mkdirs();
}

Remember give Write Storage Permission if you are using Marsmallow then given Run time Permission also.

Now you issue is that you want to create it in Internal Storage so i want to say that this code made only for Internal storage for external you can do like this :

File newfile= new File("/sdcard/"+"ordinazioni");

But check your mobile have memory card or other External Drive.
I hope this will work for you

zx485
  • 28,498
  • 28
  • 50
  • 59
Pradeep Sheoran
  • 493
  • 6
  • 15