Java FileInputStream Copy copyFile(String sourcefile, String targetfile)

Here you can find the source of copyFile(String sourcefile, String targetfile)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String sourcefile, String targetfile) 

Method Source Code

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

import java.io.*;

public class Main {
    public static void copyFile(String sourcefile, String targetfile) {
        InputStream inStream = null;
        OutputStream outStream = null;

        try {//  ww  w.j av  a  2 s.c  om
            File afile = new File(sourcefile);
            File bfile = new File(targetfile);

            inStream = new FileInputStream(afile);
            outStream = new FileOutputStream(bfile);

            byte[] buffer = new byte[1024];
            int length;

            while ((length = inStream.read(buffer)) > 0) {
                outStream.write(buffer, 0, length);
            }

            inStream.close();
            outStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(String source, String target)
  2. copyFile(String source, String targetDirectory, String filesep)
  3. copyFile(String sourceFile, String destDir, String newFileName)
  4. copyFile(String sourceFile, String destFile)
  5. copyFile(String sourceFile, String targetFile)
  6. copyFile(String sourcefile, String targetFile)
  7. copyFile(String sourceFile, String targetFolder)
  8. copyFile(String sourceFile, String targetFolder)
  9. copyFile(String sourceFilePath, String destinationFilePath)