Java FileOutputStream Write copyFile(InputStream in, File destination)

Here you can find the source of copyFile(InputStream in, File destination)

Description

copy File

License

Apache License

Declaration

public static void copyFile(InputStream in, File destination) throws Exception 

Method Source Code


//package com.java2s;
/*//from  w  w w  .j  a  va2  s  .  c o  m
 * Copyright 2015-2017 ZomboDB, LLC
 *
 * 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.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class Main {
    public static void copyFile(InputStream in, File destination) throws Exception {
        try (FileOutputStream out = new FileOutputStream(destination)) {
            byte[] bytes = new byte[65535];
            int cnt;
            while ((cnt = in.read(bytes)) > 0) {
                out.write(bytes, 0, cnt);
            }
        }
    }
}

Related

  1. copyFile(InputStream in, File destination)
  2. copyFile(InputStream input, File outFile)
  3. copyFile(InputStream input, File outputLocation)
  4. copyFile(InputStream input, OutputStream output)