title: java.io.FileNotFoundException: /storage/emulated/0/crash/crash-2016-09-04-15-35-25-1472974525277.log: open failed: ENOENT (No such file or directory)
body: <p>The following code is what I wrote for saving crash message in a local file </p>
  
  <pre><code>        try {
              long timestamp = System.currentTimeMillis();
              String time = formatter.format(new Date());
              String fileName = "crash-" + time + "-" + timestamp + ".log";
              if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                  String path = Environment
                          .getExternalStorageDirectory()
                          .getAbsolutePath()
                          + "/crash/";
                  File dir = new File(path);
                  if (!dir.exists()) {
                      dir.mkdirs();
                  }
                  FileOutputStream fos = new FileOutputStream(path + fileName);
                  fos.write(sb.toString().getBytes());
                  fos.close();
              }
              return fileName;
          } catch (Exception e) {
              Log.e(TAG, "an error occured while writing file...", e);
          }
  </code></pre>
  
  <p>But When my app crashed.The log show me some errors.It's shown as follows:</p>
  
  <pre><code>java.io.FileNotFoundException: /storage/emulated/0/crash/crash-2016-09-04-15-35-25-1472974525277.log: open failed: ENOENT (No such file or directory)
  at libcore.io.IoBridge.open(IoBridge.java:459)
  at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:87)
  at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:127)
  at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:116)
  at com.attendance.exception.CrashHandler.saveCrashInfo2File(CrashHandler.java:212)
  at com.attendance.exception.CrashHandler.handleException(CrashHandler.java:135)
  at com.attendance.exception.CrashHandler.uncaughtException(CrashHandler.java:88)
  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
  Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
  at libcore.io.Posix.open(Native Method)
  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
  at libcore.io.IoBridge.open(IoBridge.java:445)
  at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:87) 
  at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:127) 
  at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:116) 
  at com.attendance.exception.CrashHandler.saveCrashInfo2File(CrashHandler.java:212) 
  at com.attendance.exception.CrashHandler.handleException(CrashHandler.java:135) 
  at com.attendance.exception.CrashHandler.uncaughtException(CrashHandler.java:88) 
  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) 
  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 
  </code></pre>
  
  <p>I have add permissions in AndroidManifest.xml</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>What is the problem?Thanks for you help!</p>