Java Utililty Methods InputStream Copy to File

List of utility methods to do InputStream Copy to File

Description

The list of methods to do InputStream Copy to File are organized into topic(s).

Method

voidcopyStreamToFile(InputStream in, File destination)
Copy contents of specified InputStream, up to EOF, into the given destination file.
OutputStream out = null;
try {
    out = new FileOutputStream(destination);
    copyStreamToStream(in, out);
} finally {
    if (out != null) {
        out.close();
voidcopyStreamToFile(InputStream in, File out)
copy Stream To File
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(out);
    byte[] buf = new byte[1024];
    int i = 0;
    while ((i = in.read(buf)) != -1) {
        fos.write(buf, 0, i);
} finally {
    if (in != null) {
        try {
            in.close();
        } catch (IOException e) {
    if (fos != null) {
        try {
            fos.close();
        } catch (IOException e) {
booleancopyStreamToFile(InputStream in, File target)
Copy the contents of the given inputstream to given targetfile.
try {
    OutputStream out = new FileOutputStream(target);
    byte[] buf = new byte[16384];
    int c;
    while ((c = in.read(buf)) != -1)
        out.write(buf, 0, c);
    in.close();
    return true;
...
voidcopyStreamToFile(InputStream inputStream, File destFile)
copy Stream To File
File parentDir = destFile.getParentFile();
if (parentDir != null) {
    parentDir.mkdirs();
FileOutputStream fos = new FileOutputStream(destFile);
copyStream(inputStream, fos);
fos.close();
booleancopyStreamToFile(InputStream pInputStream, File pFile)
Copy an InputStream to a File
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(pFile);
} catch (FileNotFoundException e1) {
    e1.printStackTrace();
byte[] buffer = new byte[32768];
int read = 0;
...
voidcopyStreamToFile(InputStream source, File target)
Copy an input stream to a file
FileOutputStream outStream = new FileOutputStream(target);
copyInputStream(source, outStream);
voidcopyStreamToFile(InputStream stream, File destFile)
Copies data from the specified input stream to a file.
OutputStream outStream = new FileOutputStream(destFile);
copyStream(stream, outStream);
outStream.flush();
outStream.close();
voidcopyStreamToFile(InputStream stream, File destFile, long fileTime)
copy Stream To File
OutputStream outStream = new FileOutputStream(destFile);
copyStream(stream, outStream);
outStream.flush();
outStream.close();
destFile.setLastModified(fileTime);
voidcopyStreamToFile(InputStream stream, File file)
Copies the data from the InputStream to a file, then closes both when finished.
FileOutputStream output = new FileOutputStream(file);
final int oneMegabyte = 1 * 1024 * 1024;
byte[] data = new byte[oneMegabyte];
while (true) {
    int bytesRead = stream.read(data);
    if (bytesRead < 0) {
        break;
    output.write(data, 0, bytesRead);
stream.close();
output.close();