import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class CopFile_util {
public static void main(String[] args) throws IOException {
//add_file("D:\img\xaizai\163377411171847lfayul\wen");
copyFileUsingFileChannels("E:\Picture\guowang\a\1.png","E:\Picture\guowang\b\1.png","E:\Picture\guowang\b");
}
public static void copyFileUsingFileChannels(String statFile,String endFile,String url) throws IOException {
System.out.println ("statFile:"+statFile );
System.out.println ("endFile:"+endFile );
System.out.println ("url:"+url );
//创建文件夹
//File file=new File("E:\Picture\guowang\3");
File file=new File(url);
if(!file.exists()&&!file.isDirectory()) {
file.mkdirs();
}
File source = new File(statFile);
File dest = new File(endFile);
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
inputChannel = new FileInputStream (source).getChannel();
outputChannel = new FileOutputStream (dest).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
inputChannel.close();
outputChannel.close();
}
}
public static void add_file(String url){//主程序,程序入口
File file = new File(url);
//如果路径不存在,新建
if(!file.exists()&&!file.isDirectory()) {
file.mkdirs();
}
}
}