- package cn.test;
- import java.io.*;
- public class FileCopyDome {
- /**
- * @param args
- */
- public static void main(String[] args) {
- BufferedReader fis = new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter bfw;
- try {
- bfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt")));
- } catch (FileNotFoundException e1) {
- throw new RuntimeException("生成文件失败");
- }
- String line = null;
- try {
- while((line=fis.readLine())!=null){
- if("over".equals(line))
- break;
- bfw.write(line);
- bfw.newLine();
-
- }
- } catch (IOException e) {
- throw new RuntimeException("写入文件失败");
- }finally{
- try {
- if(line==null)
- bfw.close();
- } catch (IOException e) {
- throw new RuntimeException("关闭流失败");
- }
- }
- }
- }
复制代码 |