Question: I write a file in internal memory:

```
byte[] data = ... // (A buffer containing wav data)
String filename = context.getFilesDir().getAbsolutePath() + "/newout.wav";
File file = new File(filename);
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.close();

```

Then I try to play it:

```
MediaPlayer player = new MediaPlayer();
player.setDataSource(filename);
player.prepare();
player.setLooping(false);
player.start();

```

But the `prepare()` fails:

```
java.io.IOException: Prepare failed.: status=0x1

```

I checked the file and saw that it's permission is `-rw-------`. I changed it to `-rw-r--r--`, after that it was being played successfully.

So how come my app can write a file, but can't read it? And how can I make the `FileOutputStream` to set the permissions right?

Answer: 
To change programaticaly the file permissions to -rw-r--r-- you need to do smoething like this:

```
Process process = null;
DataOutputStream dataOutputStream = null;

try {
    process = Runtime.getRuntime().exec("su");
    dataOutputStream = new DataOutputStream(process.getOutputStream());
    dataOutputStream.writeBytes("chmod 644 FilePath\n");
    dataOutputStream.writeBytes("exit\n");
    dataOutputStream.flush();
    process.waitFor();
} catch (Exception e) {
    return false;
} finally {
    try {
        if (dataOutputStream != null) {
            dataOutputStream.close();
        }
        process.destroy();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

```
If you open a file, the default mode is [`Context.MODE_PRIVATE`](http://developer.android.com/reference/android/content/Context.html#MODE_PRIVATE), e.g. as in 

```
File file = new File(context.getFilesDir(), filename);

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

try {
  outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
  outputStream.write(string.getBytes());
  outputStream.close();

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

```

(taken from [the documentation](http://developer.android.com/training/basics/data-storage/files.html)). Modes `MODE_WORLD_READABLE` and `MODE_WORLD_WRITABLE` are deprecated and do not work on newer devices. So I'd say you should rather write on the external storage to make contents available to other apps.

Note: as per [documentation](http://developer.android.com/training/basics/data-storage/files.html#InternalVsExternalStorage): 

> 
> **External storage:**
> *"It's world-readable, so files saved here may be read outside of your control."*
> 
> 
>