public static File write(InputStream in, File file) throws IOException {
    Assert.notNull(in, "InputStream cannot be null");
    Assert.notNull(file, "File cannot be null");
    Assert.state(!isExisting(file) || file.canWrite(), "[%1$s] is not writable",
      tryGetCanonicalPathElseGetAbsolutePath(file));

    OutputStream out = null;

    try {
      copy(in, out = new BufferedOutputStream(new FileOutputStream(file)));
      return file;
    }
    finally {
      close(out);
    }
  }
public static File write ( InputStream in , File file ) throws IOException { Assert . notNull ( in , "InputStream cannot be null" ) ; Assert . notNull ( file , "File cannot be null" ) ; Assert . state ( ! isExisting ( file ) || file . canWrite ( ) , "[%1$s] is not writable" , tryGetCanonicalPathElseGetAbsolutePath ( file ) ) ; OutputStream out = null ; try { copy ( in , out = new BufferedOutputStream ( new FileOutputStream ( file ) ) ) ; return file ; } finally { close ( out ) ; } }
Writes the contents of the given {@link InputStream} out to the given {@link File}.

@param in the {@link InputStream} that is used as the source of the {@link File} content.
@param file the {@link File} to write the contents of the {@link InputStream} to.
@return the {@link File} be written.
@throws IOException if writing the contents of the {@link InputStream} to the {@link File}
results in an I/O error.
@throws NullPointerException if either the {@link InputStream} or {@link File} reference are null.
@throws IllegalStateException if the file exists and is not writable.
@see java.io.InputStream
@see java.io.File
@see #copy(InputStream, OutputStream)