I can not save or find file in the local storage (local storage) of my Android application

2

I have followed the Android instructions to save a file in the storage space of my App .

String filename = "myfile";
String string = "Hello world!";
FileOutputStream outputStream;

try {
      outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
      outputStream.write(string.getBytes());
      outputStream.close();
      Log.i(TAG, "writeToFile OK" );

   } catch (Exception e) {
      e.printStackTrace();
   }

Then I try to see if my file is inside a folder with the app Explorador , but I can not find it anywhere.

In the Log you can see that indeed the code enters the try since it prints writeToFile OK and there are no errors.

Why can not I find the file?

NOTE: I tried with and without the permissions indicated by Android:

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

In the documentation it is also not clear if that permission is only for writing in external storage. By the name it seems that yes. Anyway I tried with that permission and without it, and I can not find the file in any way.

    
asked by A. Cedano 07.02.2018 в 00:04
source

2 answers

3

Permission WRITE_EXTERNAL_STORAGE applies to write to external storage, reading is inherent, therefore READ_EXTERNAL_STORAGE is not required.

Internal storage does NOT require permission .

  

You can save files directly to the internal storage of the   device. By default, the files that are saved in   internal storage are private for your application and other   applications can not access them (neither the user).   When the user uninstalls your application, these files are removed.

the code you actually sample is to create a file in the internal storage:

      outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
      outputStream.write(string.getBytes());
      outputStream.close();
      Log.i(TAG, "writeToFile OK" );

Alternatively you can use getFilesDir() to save the file to internal storage.

File file = new File(getFilesDir(), filename);

To test if your file was created in truth with any of the above options in internal storage you can do it this way:

    File file = new File(getFilesDir(), filename);
    if(file.exists()){
        Log.i(TAG, "EXISTE!");
    }else{
        Log.e(TAG, "NO EXISTE!");
    }

To view the internal storage structure, you need Root permissions.

    
answered by 07.02.2018 / 00:56
source
0

Where you installed it first verify that the app has read and write permissions, since sometimes this permission is not granted and you have to manually add it, go into settings and applications and look for your app and only verify if it has permissions activated the writing part, reading.

    
answered by 07.02.2018 в 00:19