Java FileOutputStream Write copyFile(InputStream input, File outputLocation)

Here you can find the source of copyFile(InputStream input, File outputLocation)

Description

copy File

License

Open Source License

Declaration

public static File copyFile(InputStream input, File outputLocation) throws IOException 

Method Source Code


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

import java.io.File;

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

public class Main {
    public static File copyFile(InputStream input, File outputLocation) throws IOException {
        if (!outputLocation.exists()) {
            outputLocation.createNewFile();
        }/*  ww  w.j a  v  a2s  . c o m*/

        FileOutputStream dest = new FileOutputStream(outputLocation);

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = input.read(bytes)) != -1) {
            dest.write(bytes, 0, read);
        }

        return outputLocation;
    }
}

Related

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