Java FileOutputStream Write copyFile(InputStream input, OutputStream output)

Here you can find the source of copyFile(InputStream input, OutputStream output)

Description

copy File

License

Apache License

Declaration

private static long copyFile(InputStream input, OutputStream output) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    private static long copyFile(InputStream input, OutputStream output) throws IOException {
        byte buffer[] = new byte[2048];

        long count = 0;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);/* w  ww  .j a v  a2 s .c  om*/
            count += n;
        }
        return count;
    }

    private static void write(byte[] from, File file) throws IOException {
        FileOutputStream fos = new FileOutputStream(file);
        write(from, fos);
    }

    private static void write(byte[] from, OutputStream to) throws IOException {
        try {
            to.write(from);
        } finally {
            to.close();
        }
    }
}

Related

  1. copyFile(InputStream in, File destination)
  2. copyFile(InputStream in, File destination)
  3. copyFile(InputStream input, File outFile)
  4. copyFile(InputStream input, File outputLocation)
  5. copyFile(InputStream sourceFileIs, File destDirFile, String destFileName)
  6. copyFileFromAssets(InputStream inputStream, String pathToWrite)
  7. copyFileUsingFileStreams(InputStream source, File dest)
  8. copyFileUsingStream(InputStream sourceStream, File dest)