Here you can find the source of copyFile(File inFile, File outFile)
Parameter | Description |
---|---|
inFile | src file |
outFile | dest file |
public static boolean copyFile(File inFile, File outFile)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { private static final int BUFFERSIZE = 8192; /**/*from w w w . j av a 2 s.c om*/ * Copy a file * @param inFile src file * @param outFile dest file * @return true if the operation succeeded */ public static boolean copyFile(File inFile, File outFile) { FileInputStream in = null; FileOutputStream out = null; boolean success = false; try { in = new FileInputStream(inFile); out = new FileOutputStream(outFile); byte[] buffer = new byte[BUFFERSIZE]; int n; while ((n = in.read(buffer)) != -1) { out.write(buffer, 0, n); } out.flush(); success = true; } catch (IOException e) { System.err.println( "Error in copying file " + inFile.getAbsolutePath() + " to " + outFile.getAbsolutePath()); System.err.println(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { System.err.println(e); } } if (out != null) { try { out.close(); } catch (IOException e) { System.err.println(e); } } } return success; } }