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