title: Saving a text file to external storage
body: <p>I am trying to create an application that takes the accelerometer data and then save this within a text file on the device. But for some reason, it doesn't seem to be saving in external storage. It creates the folder for the file but then does not create the file nor process any of the data. Below is the method that I am working on am I missing anything obvious? </p>
  
  <pre><code>public void writeFileExternalStorage() {
      String state = Environment.getExternalStorageState();
      //external storage availability check
      if (!Environment.MEDIA_MOUNTED.equals(state)) {
          Toast.makeText(this,"NO MEDIA MOUNT",Toast.LENGTH_LONG).show();
      }
      File docsFolder = new File(Environment.getExternalStorageDirectory() + "/Documentaly");
      boolean isPresent = true;
      if (!docsFolder.exists()) {
          isPresent = docsFolder.mkdir();
          Toast.makeText(this,"Made Dir",Toast.LENGTH_SHORT).show();
      }
      if (isPresent) {
          File file = new File(docsFolder.getAbsolutePath(),"dataCollection.txt");
          Toast.makeText(this,"Made file",Toast.LENGTH_SHORT).show();
          FileOutputStream outputStream = null;
          try {
              //file.createNewFile();
              //second argument of FileOutputStream constructor indicates whether to append or create new file if one exists
              outputStream = new FileOutputStream(file, true);
              outputStream.write(entryData.getBytes());
              outputStream.flush();
              outputStream.close();
              Toast.makeText(this,"success",Toast.LENGTH_SHORT).show();
          } catch  (Exception e) {
              //Toast.makeText(this,"failure",Toast.LENGTH_SHORT).show();
              e.printStackTrace();
          }
      } else {
          // Failure
      }
  
  }
  </code></pre>