Java FileInputStream Copy copyFileUsingFileStreams(final File source, final File dest)

Here you can find the source of copyFileUsingFileStreams(final File source, final File dest)

Description

copy File Using File Streams

License

LGPL

Declaration

private static void copyFileUsingFileStreams(final File source, final File dest) throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

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

public class Main {
    private static void copyFileUsingFileStreams(final File source, final File dest) throws IOException {
        InputStream input = null;
        OutputStream output = null;
        try {/*  w  ww . j a  v a  2s.  c  o m*/
            FileInputStream _fileInputStream = new FileInputStream(source);
            input = _fileInputStream;
            FileOutputStream _fileOutputStream = new FileOutputStream(dest);
            output = _fileOutputStream;
            byte[] buf = new byte[1024];
            int bytesRead = 0;
            while (((bytesRead = input.read(buf)) > 0)) {
                output.write(buf, 0, bytesRead);
            }
        } finally {
            input.close();
            output.close();
        }
    }
}

Related

  1. copyFileToStream(File currentFile, OutputStream outputStream)
  2. copyFileToStream(File file, OutputStream stream)
  3. copyFileToStream(File file, OutputStream stream)
  4. copyFileToString(java.io.File f)
  5. copyFileToZip(final ZipOutputStream zos, final byte[] readBuffer, final File file, final int bytesInOfZip)
  6. copyFileUsingStream(File source, File dest)
  7. copyFileUsingStream(String source_path, String dest_path)