import java.util.*;
import java.io.*;
class CopyFile
{
public static void main(String[] args) throws Exception
{
File file = new File("E:\\迅雷下载");
File destFile = new File("F:\\迅雷下载");
if(!destFile.exists())
{
destFile.mkdir();
}
copyFile(file,destFile);
System.out.println("传输完成");
}
private static void copyFile(File srcFile,File destFile) throws Exception
{
File[] files = srcFile.listFiles();
for(File file:files)
{
String srcFileName = file.getName();
File aDestFile = new File(destFile,srcFileName);
copy(file,aDestFile);
}
}
private static void copy(File file,File destFile) throws Exception
{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
int len = 0;
byte[] bytes = new byte[1024];
while((len=bis.read(bytes))!=-1)
{
bos.write(bytes);
}
}
}
|
|