Here you can find the source of copyFile(String inName, String otName)
Parameter | Description |
---|---|
inName | String name of input file |
otName | String name of output file |
Parameter | Description |
---|---|
Exception | an exception |
static public void copyFile(String inName, String otName) throws Exception
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.channels.FileChannel; public class Main { /**//w w w . j ava 2 s . c o m * fast file copy utility function * @param inName String name of input file * @param otName String name of output file * @throws Exception */ static public void copyFile(String inName, String otName) throws Exception { File inFile = null; File otFile = null; try { inFile = new File(inName); otFile = new File(otName); } catch (Exception e) { e.printStackTrace(); } if (inFile == null || otFile == null) return; FileChannel sourceChannel = new FileInputStream(inFile) .getChannel(); FileChannel destinationChannel = new FileOutputStream(otFile) .getChannel(); sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel); sourceChannel.close(); destinationChannel.close(); } }