title: Why file is being overwritten in the android external storage?
body: <p>I'm trying to write student id's in a text file in the sdcard. I have already created a file named <code>students.txt</code> in my sdcard. </p>
  
  <p>The problem is that when I write a value, and read the file, I only get the last value in the file. When I open my file I can only see the last value written in it. </p>
  
  <p>What am I doing wrong? I'm writing the file in append mode using <code>outputStreamWriter</code> but still the problem remains the same.</p>
  
  <pre><code>    //function to insert
  private void myInsertFunc(String data) {
      try {
          File file = new File("/sdcard/" + FILENAME);
          FileOutputStream fileOutputStream = new FileOutputStream(file);
          OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
          outputStreamWriter.append(data);
  
          outputStreamWriter.close();
          fileOutputStream.close();
  
          Toast.makeText(getApplicationContext(), "Student ID: " + data + " Inserted Successfully!", Toast.LENGTH_SHORT).show();
      }
      catch (FileNotFoundException e) {
          e.printStackTrace();
      }
      catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  //function to read
  private void myReadFunc() {
      try {
              //InputStream inputStream = openFileInput(FILENAME);
          //InputStream inputStream = getResources().openRawResource(R.raw.student);
          File file = new File("/sdcard/" + FILENAME);
          FileInputStream fileInputStream = new FileInputStream(file);
  
          if (fileInputStream != null) {
              InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
              BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
              String receiveString = "";
              while ((receiveString = bufferedReader.readLine()) != null) {
                  //if(receiveString.contains(data))
                  //{
                      Toast.makeText(getApplicationContext(), "Student ID: " + receiveString , Toast.LENGTH_SHORT).show();
                      //break;
                  //}
              }
  
              bufferedReader.close();
              inputStreamReader.close();
              fileInputStream.close();
          }
      }
      catch (FileNotFoundException e) {
          e.printStackTrace();
      }
      catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>