0

So I'm trying to figure out where my files are stored when using openFileOutput. Where does this file get saved to on my device?

    String FILE_NAME = edit_fileName.getText().toString();
    FileOutputStream outputStream;

    try {
        outputStream = openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
    } catch (Exception e) {
        edit_fileName.setText(FILE_NAME + " could not be created/opened.");
    }

    edit_fileName.setText(getDir(FILE_NAME, Context.MODE_PRIVATE).toString());

getDir() returns "/data/data/com.myname.myapp/app_[whatever FILE_NAME is]. But when I look at my device files on my computer, I can't seem to find anything like that anywhere. No documentation I've seen has helped me.

EDIT: Updated Code:

    FileOutputStream outputStream;
    File newFile;

    newFile = new File(Environment.getExternalStorageDirectory() + FILE_NAME);

    try {
        outputStream = new FileOutputStream(newFile);
        outputStream.write("test".getBytes());
    } catch (Exception e) {
        edit_fileName.setText("Was unable to open " + FILE_NAME);
    }

This code gives me this error:

java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL

Logan Wayne
  • 6,001
  • 16
  • 31
  • 49
  • 1
    This directory is protected and you cannot access it via File Explorer unless you are rooted device – Bartosz Przybylski Oct 26 '15 at 22:18
  • @BartoszPrzybylski Is there a way I can save the file outside of the inaccessible directory? – Jacob Oaks Oct 26 '15 at 22:21
  • If you want your data to be public, you probably want to read the [External Storage documentation](http://developer.android.com/guide/topics/data/data-storage.html#filesExternal). Note that in this case, "external" just means "not private" -- it can be on internal (non-removable) memory or a removable SD card. – Snild Dolkow Oct 26 '15 at 22:21
  • @SnildDolkow Thanks, I've been associating external with SD Card, etc. – Jacob Oaks Oct 26 '15 at 22:22
  • @SnildDolkow Everything I see says external storage requires an SD Card. How can I acess internal memory through it? – Jacob Oaks Oct 26 '15 at 23:33
  • [`getExternalStorageDirectory()`](http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29) or [`getExternalStoragePublicDirectory()`](http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29) should work. Files added to those dirs may be on internal storage, or an SD card -- that's decided by the device, not your app. But regardless of the physical storage location, the files there should be accessible from your computer (and other apps). – Snild Dolkow Oct 26 '15 at 23:40
  • @SnildDolkow the updated code above gives me this error: java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL – Jacob Oaks Oct 27 '15 at 00:01
  • That problem seems like it should be a new question. Make sure to include the full callstack of the exception, and the exact file path you're using. FYI, user -2 is [`USER_CURRENT`](http://androidxref.com/6.0.0_r1/xref/frameworks/base/core/java/android/os/UserHandle.java#USER_CURRENT)... so it's a little strange that you're getting this error. [The last comment on this answer](http://stackoverflow.com/a/30146574/4811803) suggests that it has to do with trying to change other apps' files (or writing in a folder you don't have access to), but maybe yours is different. – Snild Dolkow Oct 27 '15 at 06:34

0 Answers0