Java BufferedReader read text file and store string in StringBuilder

Description

Java BufferedReader read text file and store string in StringBuilder


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] argv) {
    StringBuilder strBlder = new StringBuilder("");
    try {//from ww  w  .j av  a2  s.co  m
      BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("Main.java")));
      String line = "";
      while (null != (line = br.readLine())) {
        strBlder.append(line + "\n");
      }
      br.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    strBlder.toString();
  }
}



PreviousNext

Related