以下实例演示了使用 readline() 方法来读取文件 test.log 内容,其中 test.log 文件内容为:
菜鸟教程www.runoob.comjava 代码如下:
/*
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) {
}
}}以上代码运行输出结果为:
菜鸟教程www.runoob.comnull
以上就是Java 实例 - 读取文件内容的内容,更多相关内容请关注PHP中文网(www.php.cn)!











