public static boolean streamToFile(final InputStream inputStream,final File targetFile,final boolean doAppend){
  if (inputStream == null || !isWritable(targetFile,true)) {
    Log.e(FileUtils.class,"streamToFile(): Null parameter or can't make path dirs");
    return false;
  }
  boolean isSucceed=false;
  final int buffer_size=1024;
  OutputStream outputStream=null;
  try {
    outputStream=new FileOutputStream(targetFile,doAppend);
    byte[] bytes=new byte[buffer_size];
    int count=0;
    while ((count=inputStream.read(bytes,0,buffer_size)) > 0)     outputStream.write(bytes,0,count);
    isSucceed=true;
    outputStream.flush();
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IndexOutOfBoundsException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    if (outputStream != null)     try {
      sync(outputStream);
      outputStream.close();
    }
 catch (    IOException e) {
    }
  }
  return isSucceed;
}

public static boolean streamToFile ( final InputStream inputStream , final File targetFile , final boolean doAppend ) { if ( inputStream == null || ! isWritable ( targetFile , true ) ) { Log . e ( FileUtils . class , "streamToFile(): Null parameter or can't make path dirs" ) ; return false ; } boolean isSucceed = false ; final int buffer_size = 1024 ; OutputStream outputStream = null ; try { outputStream = new FileOutputStream ( targetFile , doAppend ) ; byte [ ] bytes = new byte [ buffer_size ] ; int count = 0 ; while ( ( count = inputStream . read ( bytes , 0 , buffer_size ) ) > 0 ) outputStream . write ( bytes , 0 , count ) ; isSucceed = true ; outputStream . flush ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IndexOutOfBoundsException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { if ( outputStream != null ) try { sync ( outputStream ) ; outputStream . close ( ) ; } catch ( IOException e ) { } } return isSucceed ; }
writes a stream to a file
