import java.io.*;
public class Test8 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static void copy(){
FileWriter fw = null; //初始化写入流并赋值为null
FileReader fr = null; //初始化读取流并赋值为nul
try {
fw = new FileWriter("E:\\sa.txt"); //创建目标文件储存目的地
fr = new FileReader("D:\\sa.txt"); //读取目标文件
char [] buf = new char[1024];
int len = 0; //数据的开始
while ((len = fr.read(buf)) != -1) {
fw.write(buf,0,len); //写入目标文件并定义数据的长度
}
}
catch (IOException e) {
throw new RuntimeException("操作失败!");
}
finally
{
if(fr != null)
try {
fr.close(); //关闭读取流
}
catch (IOException e) {
}
if(fw != null)
try {
fw.close(); //关闭写入流
}
catch (IOException e) {
}
}
}
} |