title: Android: how to write a file to internal storage
body: <p>I am developing a simple android application and I need to write a text file in internal storage device. I know there are a lot of questions (and answers) about this matter but I really cannot understand what I am doing in the wrong way.</p>
  
  <p>This is the piece of code I use in my activity in order to write the file:</p>
  
  <pre><code>public void writeAFile(){
      String fileName = "myFile.txt";
      String textToWrite = "This is some text!";
      FileOutputStream outputStream;
  
     try {
        outputStream = openFileOutput(fileName , Context.MODE_PRIVATE);
        outputStream.write(textToWrite.getBytes());
        outputStream.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
  }
  </code></pre>
  
  <p>I really cannot understand which mistake I am doing. In addition, I have tried <a href="http://www.journaldev.com/9383/android-internal-storage-example-tutorial" rel="noreferrer">this</a> project on my emulator in Android Studio and my phone in order to understand where I am doing something wrong but even with that project no file is written neither on the phone or on the emulator.</p>
  
  <p>EDIT:
  I know that no file is written to my internal storage because I try to read the content of the file, after I have written to it, with this code:</p>
  
  <pre><code>public void ReadBtn(View v) {
      //reading text from file
      try {
          FileInputStream fileIn=openFileInput("myFile.txt");
          InputStreamReader InputRead= new InputStreamReader(fileIn);
  
          char[] inputBuffer= new char[READ_BLOCK_SIZE];
          String s="";
          int charRead;
  
          while ((charRead=InputRead.read(inputBuffer))&gt;0) {
              String readstring=String.copyValueOf(inputBuffer,0,charRead);
              s +=readstring;
          }
          InputRead.close();
          textmsg.setText(s);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Nothing is shown at all.</p>