import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile {
/**
* 文件复制
* @param src 源文件
* @param dst目标文件
*/
public static void copy(File src, File dst) {
try {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(src),1024);
out = new BufferedOutputStream(new FileOutputStream(dst),1024);
byte[] buffer = new byte[1024];
int len;
while ((len=in.read(buffer))!=-1) {
out.write(buffer,0,len);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
File file1=new File("E:/123.xls");//源文件
if (file1.exists()) {//文件是否存在
File file2=new File("D:/"+file1.getName());//目标文件
copy(file1, file2);
}else {
System.out.println("源文件不存在。");
}
}
}
IO 流实现.一个读一个写...
就是一个简单的IO流啊,一楼写的很全了,嘎嘎