/**
* 对IO的学习-讲一个文件的内容写入到另一个文件中
* @author dlding
* @
*/
public class MyIODemon02 {
/**
*
* @param pathin 要读取的文件的路径
* @param pathout要写入的文件的路径
*/
public static void MyBufferReader(String pathin,String pathout)
{
File filein=new File(pathin);//要读取的文件
File fileout=new File(pathout);//要写入的文件
FileReader fr=null;
BufferedReader bf=null;
FileWriter fw=null;
BufferedWriter bw=null;
try {
fr=new FileReader(filein);
bf=new BufferedReader(fr);
fw=new FileWriter(fileout);
bw=new BufferedWriter(fw);
String str=bf.readLine();
while(null != str)
{
bw.write(str);
bw.newLine();
str=bf.readLine();
}
bw.flush();//将缓存中的数据写入文件
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
bf.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}