Java File Copy fileCopy(String sFrom, String sTo)

Here you can find the source of fileCopy(String sFrom, String sTo)

Description

file Copy

License

Open Source License

Declaration

public static synchronized void fileCopy(String sFrom, String sTo) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static synchronized void fileCopy(String sFrom, String sTo) throws IOException {

        File f1 = new File(sFrom);
        File f2 = new File(sTo);
        InputStream in = new FileInputStream(f1);
        OutputStream out = new FileOutputStream(f2);

        byte[] buf = new byte[1024];
        int len;/*from   w w  w  . j  a v a2s  .  c  om*/
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
        System.out.println("File copied.");

    }
}

Related

  1. FileCopy(InputStream input, OutputStream output, int bufferSize)
  2. fileCopy(String from, String to)
  3. fileCopy(String from, String to)
  4. fileCopy(String fromPath, String toPath)
  5. fileCopy(String oldFilePath, String newFilePath, boolean isCover)
  6. fileCopy(String source, String target)
  7. fileCopy(String sourceFile, String destinationFile)
  8. fileCopy(String sourcefile, String destinctionFile)
  9. workaroundCopyFile(final File src, final File dest)