Here you can find the source of copy(File inFile, File outFile)
Parameter | Description |
---|---|
inFile | the source filename |
outFile | the target filename |
public static boolean copy(File inFile, File outFile)
//package com.java2s; import java.nio.channels.FileChannel; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**//from w ww. j a va 2 s . c om * This method copies one file to another location * * @param inFile the source filename * @param outFile the target filename * @return true on success */ public static boolean copy(File inFile, File outFile) { if (!inFile.exists()) { return false; } FileChannel in = null; FileChannel out = null; try { in = new FileInputStream(inFile).getChannel(); out = new FileOutputStream(outFile).getChannel(); long pos = 0; long size = in.size(); while (pos < size) { pos += in.transferTo(pos, 10 * 1024 * 1024, out); } } catch (IOException ioe) { ioe.printStackTrace(); return false; } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { return false; } } return true; } }