import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class copyfile {
public static void main(String[] args) {
String sourceFile="E:/Workspaces/MyEclipse 10/yidong/src/a.txt";
String targetFile="E:/Workspaces/MyEclipse 10/yidong/src/b.txt";
copy01(sourceFile,targetFile);
}
public static void copy01(String sourceFile,String targetFile)
{
// 创建对象
FileReader fr=null;
FileWriter fw=null;
try {
fr=new FileReader(sourceFile);
fw=new FileWriter(targetFile);
// 循环读和循环写
int len=0;
while((len=fr.read())!=-1)
{
fw.write((char)len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally
{
if(fr!=null)
{
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(fw!=null)
{
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
自己还是要多加练习
2018年7月13日17:49:59于易动学院