希望对你有帮助FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while((i = fis.read(buf))!=-1){
fos.write(buf, 0, i);
}
fis.close();
fos.close();
------------整个目录下--------------------
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class CopyFile {
private static String sourcepath;
private static String destpath;
//处理参数
private void processArgs(String[] args) {
if (args.length != 2) {
System.out.println("请输入两个文件目录……");
System.exit(1);
}//end if
else {
sourcepath = args[0];
destpath = args[1];
}//end else
}//end processArgs
//拷贝文件
private void copyFile(String source, String dest) {
try {
File in = new File(source);
File out = new File(dest);
FileInputStream inFile = new FileInputStream(in);
FileOutputStream outFile = new FileOutputStream(out);
byte[] buffer = new byte[1024];
int i = 0;
while ((i = inFile.read(buffer)) != -1) {
outFile.write(buffer, 0, i);
}//end while
inFile.close();
outFile.close();
}//end try
catch (Exception e) {
}//end catch
}//end copyFile
//处理目录
public void copyDict(String source, String dest) {
String source1;
String dest1;
File[] file = (new File(source)).listFiles();
for (int i = 0; i < file.length; i++)
if (file[i].isFile()) {
source1 = source + "/" + file[i].getName();
dest1 = dest + "/" + file[i].getName();
copyFile(source1, dest1);
}//end if
for (int i = 0; i < file.length; i++)
if (file[i].isDirectory()) {
source1 = source + "/" + file[i].getName();
dest1 = dest + "/" + file[i].getName();
File dest2 = new File(dest1);
dest2.mkdir();
copyDict(source1, dest1);
}//end if
}//end copyDict
public static void main(String args[]) {
CopyFile copyFile = new CopyFile();
copyFile.processArgs(args);
copyFile.copyDict(sourcepath, destpath);
}
}//end CopyFile