IO文件读写

作者在 2008-11-24 09:52:57 发布以下内容

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Text {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
   try{
     
      File read = new File("E:\\sk.txt");
      File write = new File("E:\\sk1.txt");
     
      BufferedReader br = new BufferedReader(new FileReader(read));
      BufferedWriter bw = new BufferedWriter(new FileWriter(write));
      String temp = null;
      temp = br.readLine();
      while(temp != null){
       //写文件
       bw.write(temp + "\r\n"); //只适用Windows系统
       //继续读文件
       temp = br.readLine();
      }
     
      bw.close();
      br.close();
     
     }catch(FileNotFoundException e){ //文件未找到
      System.out.println (e);
     }catch(IOException e){
      System.out.println (e);
     }

}
}

默认分类 | 阅读 3288 次
文章评论,共0条
游客请输入验证码
浏览42512次
文章分类