title: Android: write failed: EPIPE (Broken pipe) Error on write file
body: <p>I was trying to take screenshot of the Android screen programatically. I had done the following code:</p>
  
  <pre><code>private void getsnap(){
      try{
          Process sh = Runtime.getRuntime().exec("su", null, null);
          OutputStream os = sh.getOutputStream();
          String filePath = this.getFilesDir().getPath().toString() + "/fileName1.jpeg";
          os.write(("/system/bin/screencap -p " + filePath).getBytes("ASCII"));
          os.flush();
          os.close();
          sh.waitFor();       
      } 
      catch (Exception e) 
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <blockquote>
    <p><code>java.io.IOException: write failed: EPIPE (Broken pipe)</code></p>
  </blockquote>
  
  <p>Please can someone help? I had already checked the other posts and I dont find anything solving my issue. </p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Please note, the Error happens in the line <code>os.write()</code>.</p>