Q:

Can't Delete local File - Error "Is a Directory"

I have searched the vast Internet with no success. I am writing a file and then trying to delete it. My code has some commented out statements where I have tested it writing a file with contents both from a simple string, this works. However, when I try to make it create a file from an EditText (casted to a String) it has an error. I don't understand.
Someone please help me with this issue. 
When I press the delete button, this error comes up:
04-14 11:40:38.086  24584-24584/com.test.dev.write_delete_local_file E/Exception﹕ File write failed: java.io.FileNotFoundException: /data/data/com.test.dev.write_delete_local_file/files: open failed: EISDIR (Is a directory)

MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editName = (EditText)findViewById(R.id.nameEdit);
    editContent = (EditText)findViewById(R.id.contentEdit);
    btnWrite = (Button)findViewById(R.id.btnWrite);
    btnDelete = (Button)findViewById(R.id.btnDelete);

    fileContents = (String) editContent.getText().toString();
    fileName = (String) editName.getText().toString();

    btnWrite.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){

            writeFile(fileName, fileContents);
        }

    });

    btnDelete.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            deleteTheFile(fileName);
        }

    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

private void writeFile(String name, String data) {
    try {
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(openFileOutput(name, Context.MODE_PRIVATE));
        //OutputStreamWriter outputStreamWriter = new OutputStreamWriter(openFileOutput("test.txt", Context.MODE_PRIVATE));
        outputStreamWriter.write(data);
        //outputStreamWriter.write("abcdefghijklmnop");
        outputStreamWriter.close();

        Toast.makeText(this.getBaseContext(), (CharSequence) this.getFilesDir().toString(), Toast.LENGTH_SHORT).show();
    }
    catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }
}

public void deleteTheFile(String name){
    File chosenFile = context.getFileStreamPath(name);
    //File chosenFile = this.getFileStreamPath("test.txt");
    boolean fileDeleted = chosenFile.delete();
    if (fileDeleted) {
        Log.d(TAG, name + " was deleted");
    } else {
        Log.d(TAG, name + " was not deleted");
    }

}

A:

I think it's because your file name is initialized in onCreate method, so in case if your editText doesn't have text in XML layout definition, fileName will be empty. 
You should invoke (String) editName.getText().toString() in btnDelete click listener. Or set text change listener for editText and update fileName field every time when text changes.

