Java FileInputStream Copy copyFile(String from, String to)

Here you can find the source of copyFile(String from, String to)

Description

copy File

License

Apache License

Declaration

public static boolean copyFile(String from, String to) 

Method Source Code

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

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

public class Main {
    public static boolean copyFile(String from, String to) {
        File fromFile, toFile;/*from   ww  w .  j av a  2  s .  co  m*/
        fromFile = new File(from);
        toFile = new File(to);
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            toFile.createNewFile();
            fis = new FileInputStream(fromFile);
            fos = new FileOutputStream(toFile);
            int bytesRead;
            byte[] buf = new byte[4 * 1024];
            while ((bytesRead = fis.read(buf)) != -1) {
                fos.write(buf, 0, bytesRead);
            }
            fos.flush();
            fos.close();
            fis.close();
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}

Related

  1. copyFile(String f1, String f2)
  2. copyFile(String fileIn, String fileOut)
  3. copyFile(String fileInName, String fileOutName)
  4. copyFile(String fileName, String fromDir, String toDir)
  5. copyFile(String fileOutPut, String fileIn)
  6. copyFile(String fromFile, String toFile)
  7. copyFile(String fromFilePath, String toFilePath)
  8. copyFile(String inFile, String outFile)
  9. copyFile(String inFileName, String outFileName)