Java FileInputStream Copy copyFile(OutputStream out, InputStream in)

Here you can find the source of copyFile(OutputStream out, InputStream in)

Description

copy File

License

Creative Commons License

Declaration

static protected void copyFile(OutputStream out, InputStream in) throws IOException 

Method Source Code


//package com.java2s;
/* Studio for kdb+ by Charles Skelton
   is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License
   http://creativecommons.org/licenses/by-nc-sa/3.0
   except for the netbeans components which retain their original copyright notice
*///from w ww.j  av  a  2 s. c o  m

import java.io.*;

public class Main {
    static protected void copyFile(OutputStream out, InputStream in) throws IOException {
        byte buffer[] = new byte[4096];

        while (true) {
            int r = in.read(buffer);
            if (r <= 0)
                break;
            out.write(buffer, 0, r);
        }
    }

    static protected void copyFile(OutputStream out, String infile) throws IOException {
        FileInputStream fin = new FileInputStream(infile);
        copyFile(out, fin);
        fin.close();
    }
}

Related

  1. copyFile(final String sourceFilePath, final String destFilePath)
  2. copyFile(final String sSource, final String sDest)
  3. copyFile(InputStream in, File dst)
  4. copyFile(InputStream in, File to)
  5. copyFile(InputStream in, String destFile)
  6. copyFile(String f1, String f2)
  7. copyFile(String fileIn, String fileOut)
  8. copyFile(String fileInName, String fileOutName)
  9. copyFile(String fileName, String fromDir, String toDir)