static public long writeToFile ( InputStream in , String fileOutName ) throws IOException { try ( FileOutputStream fout = new FileOutputStream ( fileOutName ) ) { OutputStream out = new BufferedOutputStream ( fout ) ; return IO . copy ( in , out ) ; } finally { if ( null != in ) in . close ( ) ; } }
copy input stream to file . close input stream when done .