How can I create a folder in the internal memory in Android?

0

I can not find the way to create a folder on android. With java it is different than creating it in Windows.

How can I create a folder in the internal memory of a java phone?

    
asked by Diego 11.02.2017 в 23:18
source

2 answers

3

If you want to create a folder in private memory, you do it with:

File nuevaCarpeta = new File(getFilesDir(), "miCarpeta");
nuevaCarpeta.mkdirs();

If you want to create a folder in the external memory, whether it is a fixed memory or SD card, you first need to add a privilege to the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

then you create it as:

File nuevaCarpeta = new File(getExternalStorageDirectory(), "miCarpeta");
nuevaCarpeta.mkdirs();

As you can see, it's not that different from Java.

More information is available at data storage , a part of the official documentation that It is already translated into Spanish.

The link also mentions that you have to discriminate between apps with Android 4.3- and Android 4.4+ Pre 4.4 you could not access SD cards using getExternalFilesDir() on devices that had part of the fixed memory as an external file system , since 4.4 there is getExternalFilesDirs() that returns an array of folders for external data.

    
answered by 11.02.2017 / 23:37
source
0
    File ruta_sd = Environment.getExternalStorageDirectory();
    File nuevaCarpeta = new File(ruta_sd.getAbsolutePath(), "miCarpeta");

It works perfectly for me, tmb I can create folders inside other folders in external memory, just do this:

    nuevaCarpeta2  = new File(ruta_sd.getAbsolutePath()+"/miCarpeta", "otraCarpeta");
    
answered by 29.06.2017 в 00:46