code: public static boolean writeStream(File file, InputStream stream, boolean append) throws IOException {
          OutputStream o = null;
          try {
              makeDirs(file.getAbsolutePath());
              o = new FileOutputStream(file, append);
              byte data[] = new byte[1024];
              int length = -1;
              while ((length = stream.read(data)) != -1) {
                  o.write(data, 0, length);
              }
              o.flush();
              return true;
          } finally {
              closeQuietly(o);
              closeQuietly(stream);
          }
      }
docs: write file
  
  @param file   the file to be opened for writing.
  @param stream the input stream
  @param append if <code>true</code>, then bytes will be written to the end of the file rather than the beginning
  @return return true
  @throws IOException if an error occurs while operator FileOutputStream