Java BufferedInputStream Copy copyFileToStream(File from, OutputStream out)

Here you can find the source of copyFileToStream(File from, OutputStream out)

Description

copy File To Stream

License

Open Source License

Declaration

public static void copyFileToStream(File from, OutputStream out) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    private static final byte[] BUFFER = new byte[64 * 1024];

    public static void copyFileToStream(File from, OutputStream out) throws IOException {
        InputStream in = new BufferedInputStream(new FileInputStream(from));
        try {// w  w w. j a  v  a  2 s. c o m
            copyStream(in, out);
        } finally {
            in.close();
        }
    }

    public static void copyStream(InputStream in, OutputStream out) throws IOException {
        while (true) {
            int read = in.read(BUFFER);
            if (read < 0)
                break;
            out.write(BUFFER, 0, read);
        }
    }
}

Related

  1. copyFileBytes(String srcFileName, String tarFileName)
  2. copyFileFromStream(InputStream in, File dest)
  3. copyFileFromZipToDir(String zipFile, String fileNamePattern, File dir)
  4. copyFileNormal(File copyFrom, File copyTo)
  5. copyFileToFile(File in, File out)
  6. copyFileToStream(File input, OutputStream os)
  7. copyFileToTemp(InputStream is, String dirName, String fileName)
  8. copyFileUnique(File in, File outDir)