I've been trying to read and write to a text file from Android studio, and keep getting the "Permission denied" exception. I've read through the different posts,and still can't seem to solve it. 
My code:
public void buttonSave(View view) {
    //File directory = new File(path);
    File directoryFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "");
    directoryFile.mkdirs();
    File file = new File(directoryFile, "savefile.txt");
    try {
        file.createNewFile();
    } catch (IOException e) {;}
    eV = (EditText)findViewById(R.id.editText_box);
    String[] editTextValue = eV.getText().toString().split(" ");
    Save(file, editTextValue);
}
public void Save(File file, String[] data){
    FileOutputStream foe = null;
    Toast.makeText(getApplicationContext(), Integer.toString(data.length), Toast.LENGTH_SHORT).show();
    try {
        foe = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
    }
    try {
        for (int i=0; i<data.length; i++){
            foe.write(data[i].getBytes());
            if (i<data.length){
                foe.write("\n".getBytes());
            }
        }
    } catch (IOException e) {};
    try {
        foe.close();
    } catch (IOException e) {};
}
And my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="home.learningapp2">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Any suggestions? It doesn't work on the emulator or when I run it on my phone.
 
     
     
    