.txt读写

public static void main(String[] args) throws IOException {

  File fileTxt = new File("D://uuuuuuuupload//Testlist.txt");
  String str1 = new String();

  //StringBuffer str2 = new StringBuffer();  
  StringBuilder str2 = new StringBuilder(); //效率更高,但线程不安全

  //读取原文本
  BufferedReader input = new BufferedReader(new FileReader(fileTxt));
  while ((str1 = input.readLine()) != null) {
  str2.append(str1 + "\r\n");
  }
  System.out.println(str2.toString());
  input.close();

  //追加字符串
  str2.append("=========" );

  //重新写入
  BufferedWriter output = new BufferedWriter(new FileWriter(fileTxt));
  output.write(str2.toString());
  output.close();

}

 

posted @ 2018-03-01 11:19  AsapRun  阅读(104)  评论(0)    收藏  举报