import java.io.*;
public class 复制文件 {
public static void main(String[] args) throws Exception{
File f1 = new File("d:\\小苹果.mp3");
File f2 = new File("e:\\小苹果.mp3");
copy(f1 , f2);
}
private static void copy(File f1 , File f2) throws Exception{
InputStream input = new FileInputStream(f1);
OutputStream output = new FileOutputStream(f2);
//1M = 1024000字节
byte b[] = new byte[8000];
int count = 0;
//返回读入缓冲区数组的字节总数,如果已经到达文件末尾,则返回-1。
while((count = input.read(b)) != -1)
{
output.write(b, 0, count);
}
output.close();
input.close();
}
}