/*
通过缓冲区复制一个java文件
*/
import java.io.*;
class CopyTextbybuf
{
public static void main(String[] args)
{
BufferedReader bufr = null;
BufferedWriter bufw = null;
try
{
bufr = new BufferedReader(new FileReader("BufferedReaderDemo.java"));
bufw = new BufferedWriter(new FileWriter("CopyTextbybuf.txt"));
String line = null;
while ((line = bufr.readLine())!= null)
{
bufw.writer(line);
bufw.newLine();
bufw.flush();
}
}
catch (IOException e)
{
throw new RuntimeException("读写失败");
}
finally
{
try
{
if (bufr!=null)
{
bufr.close();
}
}
catch (IOException e)
{
throw new RuntimeException("读取关闭失败");
}
try
{
if (bufw != null)
{
bufw.close();
}
}
catch (IOException e)
{
throw new RuntimeException("写入关闭失败");
}
}
}
}
|
|