title: open Failed:EROFS read only file system android
body: <p>I am trying to play a sound and record it from a phone's microphone then write it to a file (3gp format).<br>
  I used threads from some testing purposes. the problem is I get an error like </p>
  
  <pre><code>&gt; caused by libcore.io.ErrnoException: open failed: EROFS (read only file system)
  </code></pre>
  
  <p>though I'm not trying to acess any system files.
  I looked around and found <a href="https://stackoverflow.com/questions/15711098/trying-to-create-a-file-in-android-open-failed-erofs-read-only-file-system">this</a>: </p>
  
  <p>I added both Write/read permissions but still it doesn't work.</p>
  
  <p>Here's the code generating the error:</p>
  
  <pre><code>public void startRecording(){
  
      MediaRecorder mRecorder = new MediaRecorder();
      mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      mRecorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"xfile.3gp");
      mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      try {
          mRecorder.prepare();
          mRecorder.start();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>and the thread blocks:</p>
  
  <pre><code>super.onCreate(savedInstanceState);  
   setContentView(R.layout.activity_main);
  
  Thread thread=new Thread(new Runnable()
  {
      public void run()
      {
          try 
          {
              genTone();
          } 
          catch (IOException e) 
          {
              // TODO Auto-generated catch block                                                                                                                                                                                          
              e.printStackTrace();
          }
          handler.post(new Runnable()
          {
              public void run()
              {
                  playSound();
              }                                                                                    });
      }
  });
  thread.start();
  </code></pre>
  
  <p>Play Sound Method</p>
  
  <pre><code>void playSound(){
          AudioTrack audioTrack= null;
          try{
          audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length, AudioTrack.MODE_STATIC);
          audioTrack.write(generatedSnd, 0, generatedSnd.length);
  
          audioTrack.play();
          Thread thr=new Thread(new Runnable(){
              public void run(){
                  startRecording();
              }
          });
          thr.start();
  
          }
          catch(Exception e)
          {
              System.out.print(e);
          }
  }
  </code></pre>