Home >Java >javaTutorial >Java Example - Reading File Contents

Java Example - Reading File Contents

黄舟
黄舟Original
2017-02-15 10:06:271511browse

The following example demonstrates using the readLine() method to read the content of the file test.log, where the content of the test.log file is:

菜鸟教程www.runoob.com
java The code is as follows:
/*
 author by runoob.com
 Main.java
 */import java.io.*;public class Main {
   public static void main(String[] args)  {
      try {
         BufferedReader in = new BufferedReader
         (new FileReader("test.log"));
         String str;
         while ((str = in.readLine()) != null) {
            System.out.println(str);
         }
         System.out.println(str);
      } catch (IOException e) {
      }
   }}

The above code runs The output result is:

菜鸟教程www.runoob.comnull

The above is the Java example - reading the content of the file. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn