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

Java Example - Reading File Contents

黄舟
Release: 2017-02-15 10:06:27
Original
1515 people have browsed it

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
Copy after login
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) {
      }
   }}
Copy after login

The above code runs The output result is:

菜鸟教程www.runoob.comnull
Copy after login

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)!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template