Java FileInputStream Copy copyFile(String fromFilePath, String toFilePath)

Here you can find the source of copyFile(String fromFilePath, String toFilePath)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String fromFilePath, String toFilePath) throws Exception 

Method Source Code


//package com.java2s;

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

import java.io.FileOutputStream;

import java.io.InputStream;

public class Main {
    public static void copyFile(String fromFilePath, String toFilePath) throws Exception {

        int bytesum = 0;
        int byteread = 0;
        File oldfile = new File(fromFilePath);
        if (oldfile.exists()) {
            InputStream inStream = new FileInputStream(fromFilePath);
            FileOutputStream fs = new FileOutputStream(toFilePath);
            byte[] buffer = new byte[1444];
            while ((byteread = inStream.read(buffer)) != -1) {
                bytesum += byteread;/* w  w  w  . ja va 2  s  .co m*/
                System.out.println(bytesum);
                fs.write(buffer, 0, byteread);
            }
            inStream.close();
        }
    }
}

Related

  1. copyFile(String fileInName, String fileOutName)
  2. copyFile(String fileName, String fromDir, String toDir)
  3. copyFile(String fileOutPut, String fileIn)
  4. copyFile(String from, String to)
  5. copyFile(String fromFile, String toFile)
  6. copyFile(String inFile, String outFile)
  7. copyFile(String inFileName, String outFileName)
  8. copyFile(String input, String output)
  9. copyFile(String inputFile, String outputFile)