Android: write failed: EPIPE (Broken pipe) Error on write file

view story

http://stackoverflow.com – I was trying to take screenshot of the Android screen programatically. I had done the following 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(); (HowTos)