import java.io.*;
public class CopyTest
{
public static void main(String[] args)
{
BufferedReader bfr=null;
BufferedWriter bfw=null;
try
{
bfr=new BufferedReader(new FileReader("test.txt"));
bfw=new BufferedWriter(new FileWriter("copy.txt"));
String line=null;
while ((line=bfr.readLine())!=null)
{
bfw.write(line);
bfw.newLine();
bfw.flush();
}
}
catch (IOException e)
{
throw new RuntimeException("读取失败");
}
finally
{
try
{
if (bfr!=null)
{
bfr.close();
}
}
catch (IOException e)
{
throw new RuntimeException("关闭失败");
}
try
{
if (bfw!=null)
{
bfw.close();
}
}
catch (IOException e)
{
throw new RuntimeException("关闭失败");
}
}
}
} |