title: Writing File to External Storage (Android Studio) Not working, but no errors?? Tried eveything
body: <p><a href="https://i.stack.imgur.com/d2QGb.jpg" rel="nofollow noreferrer">Upon request, here is the log file when I press the button</a>   I have scoured the internet, this forum, and youtube to try to figure out how to write a simple txt file to external storage. I found this great tutorial on youtube:</p>
  
  <p><a href="https://www.youtube.com/watch?v=kerqarY7_wQ" rel="nofollow noreferrer">https://www.youtube.com/watch?v=kerqarY7_wQ</a></p>
  
  <p>And I followed his code to the tee. However, when I call the method shown below, nothing happens. No exceptions are thrown, the file isn't created, and I don't see any of my fail-safe messages pop up on the screen through Toast. What is happening?!?! I made sure to add the permissions to the manifest file, and the buttons definitely call the correct methods. For reference, I tried his tutorial on writing to internal storage and it works perfectly. I don't understand how it can just not show any messages, because even if it couldn't write to storage it should have told me. The code is below, I would really appreciate any help.</p>
  
  <pre><code>    //Permissions files in Manifest:
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&gt;&lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"&gt;&lt;/uses-permission&gt;
  
      //Method in main java file
      public void writeExternalStorage(View view) {
  
      String state = Environment.getExternalStorageState();
  
      if(Environment.MEDIA_MOUNTED.equals(state)) {
          File root = Environment.getExternalStorageDirectory();
          File Dir = new File(root.getAbsolutePath()+"/MyAppFile");
  
          if(!Dir.exists()) {
              Dir.mkdir();
          }
  
          File file = new File(Dir,"Test.txt");
          String message = editText.getText().toString();
          try {
              FileOutputStream fileOutputStream = new FileOutputStream(file);
              fileOutputStream.write(message.getBytes());
              fileOutputStream.close();
              //the editText variable is the text field on the app.
              editText.setText("");
              Toast.makeText(getApplicationContext(), "Message Saved!",Toast.LENGTH_LONG).show();
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
  
      } else {
          Toast.makeText(getApplicationContext(), "SD Card not found.",Toast.LENGTH_LONG).show();
  
      }
  
  
  }
  </code></pre>