Java BufferedInputStream Copy copyFile(InputStream src, File dst)

Here you can find the source of copyFile(InputStream src, File dst)

Description

copy File

License

Apache License

Declaration

public static void copyFile(InputStream src, File dst) 

Method Source Code


//package com.java2s;
/*/*from  ww  w. jav  a2 s .  c o m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import java.io.InputStream;
import java.io.OutputStream;

public class Main {

    public static void copyFile(InputStream src, File dst) {
        int BUFFER_SIZE = 16 * 1024;
        try {

            InputStream in = null;
            OutputStream out = null;
            try {
                in = new BufferedInputStream(src, BUFFER_SIZE);
                out = new BufferedOutputStream(new FileOutputStream(dst), BUFFER_SIZE);
                byte[] buffer = new byte[BUFFER_SIZE];
                while (in.read(buffer) > 0) {
                    out.write(buffer);
                }
            } finally {
                if (null != in) {
                    in.close();
                }
                if (null != out) {
                    out.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(final File sourceFile, final File targetFile)
  2. copyFile(final File src, final File dest)
  3. copyFile(final File to, final File from)
  4. copyFile(InputStream is, File newFile)
  5. copyFile(InputStream src, File dest)
  6. copyFile(String dest_path, String src_path)
  7. copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)
  8. copyFile(String from, String to)
  9. copyFile(String fromFile, String toFile)