Create a txt file on Android in a public way? [closed]

0

How to correctly use getExternalStorageDirectory () to create text files that can be viewed by the user. Regardless of whether I have an external memory or not.

    
asked by Eduardo Castro 23.08.2017 в 01:58
source

1 answer

2

Every Android device has shared external storage, either an SD memory, or virtualized. Simply use the external memory system to store your data, an example could be:

try {
    File nuevaCarpeta = new File(Environment.getExternalStorageDirectory(), "CarpetaDePrueba");
if (!nuevaCarpeta.exists()) {
    nuevaCarpeta.mkdir();
}
try {
    File file = new File(nuevaCarpeta, "Archivo" + ".txt");
    file.createNewFile();
} catch (Exception ex) {
    Log.e("Error", "ex: " + ex);
}
} catch (Exception e) {
Log.e("Error", "e: " + e);
}

Without forgetting the permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
answered by 23.08.2017 / 10:00
source