Here you can find the source of copyFiles(final File fromFile, final File toFile)
Parameter | Description |
---|---|
fromFile | a parameter |
toFile | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFiles(final File fromFile, final File toFile) throws IOException
//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; import java.nio.channels.FileChannel; public class Main { /**//from w w w .ja va 2 s.c o m * Copies the contents of the input file to the output file * @param fromFile * @param toFile * @throws IOException */ public static void copyFiles(final File fromFile, final File toFile) throws IOException { FileInputStream inFile = new FileInputStream(fromFile); FileOutputStream outFile = new FileOutputStream(toFile); FileChannel inChannel = inFile.getChannel(); FileChannel outChannel = outFile.getChannel(); int bytesWritten = 0; long byteCount = inChannel.size(); while (bytesWritten < byteCount) { bytesWritten += inChannel.transferTo(bytesWritten, byteCount - bytesWritten, outChannel); } inFile.close(); outFile.close(); } }