java中BufferedReader和BufferedWriter的讲解

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class Byte2Character {
 
 
 public static void main(String[] args) throws Exception {
  
//  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
//  String str = null;
//  StringBuilder builder = new StringBuilder();
//  while((str = bufferedReader.readLine()) != "\t\n")
//  {
//   
//   builder.append(str);
//  }
//  bufferedReader.close();
  
  BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("a.doc"));
  bufferedWriter.write("我是中国人asd");
  bufferedWriter.close();
  
  BufferedReader bufferedReader = new BufferedReader(new FileReader("a.doc"));
  String str = null;
  StringBuilder builder = new StringBuilder();
  while((str = bufferedReader.readLine()) != null)
  {
   builder.append(str);
  }
  bufferedReader.close();
  System.out.println(builder);
 }
//附录

readLine

public String readLine()   throwsIOException

读取一个文本行。通过下列字符之一即可认为某行已终止:换行 ('\n')、回车 ('\r') 或回车后直接跟着换行。

返回: 包含该行内容的字符串,不包含任何行终止符,如果已到达流末尾,则返回 null

你可能感兴趣的:(java语言,java,string,character,exception,null,import)