Java Examples - Read File Content

Java 实例Java Examples

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

Example
www.example.com

The Java code is as follows:

Main.java file

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 output of the above code is:

Example
www.example.com
null

Java 实例Java Examples

Other Extensions