[JAVA] What is the BufferedReader class?

What is the BufferedReader class? A class for reading text files. There is a readline method that reads a text file line by line. There is also a FileReader class, but it seems to be inefficient because it reads characters one by one.

public class Main {
  public static void main(String[] args) {

    //Check if the file exists by specifying it.
    File file = new File("c:\\Sample\\Test.txt");
    if(!file.exists()){
      System.out.print("File does not exist");
      return;
    }

    //Instead of reading the specified file, the file to be read is specified.
    FileReader fileReader = new FileRreader(file);
    //The specified file is being read.
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    String data;
    //Read line by line with the readLine method until a null value is output.
    while((data = bufferReader.readLine()) != null){
      System.out.println(data)
    }

    fileReader.close();
    
    //Error output.
  } catch(IOException e) {
    e.printStaticTrace();
  }
}

A memo of each class that came out. File class // Specify the file to operate FileReader class // Specify the file to read BufferedReader class // Reading a file.

Recommended Posts

What is the BufferedReader class?
What is the pluck method?
[Java] What is class inheritance?
What is the constructor for?
[Java basics] What is Class?
What is the initialize method?
What is the difference between a class and a struct? ?? ??
'% 02d' What is the percentage of% 2?
[Swift] What is "inheriting a class"?
What is the LocalDateTime class? [Java beginner] -Date and time class-
What is Cubby
When the bean class name is duplicated
What is Docker?
What is a class in Java language (3 /?)
What is null? ]
What is the right migration data type? ??
What is Keycloak
What is testing? ・ About the importance of testing
What is maven?
What is Jackson?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is the best file reading (Java)
What is a class in Java language (1 /?)
What is params
What is SLF4J?
What is a class in Java language (2 /?)
What is Facade? ??
What is the model test code testing
What is Java <>?
What is Gradle?
What is POJO
What is the main method in Java?
What is Java
What is the data structure of ActionText?
What is the Facade pattern useful for?
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is Pullback doing in The Composable Architecture
What is JSP? ~ Let's know the basics of JSP !! ~
What is the Java Servlet / JSP MVC model?
What is different from the PHP language. [Note]
What is the volatile modifier for Java variables?
What is the difference between SimpleDateFormat and DateTimeFormatter? ??
What is Maven Assembly?
About the StringBuilder class
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is Ruby's self?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?