例子
以下示例显示java.io.BufferedReader.readline()方法的用法。
package com.jc2182;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
public class BufferedReaderDemo {
public static void main(String[] args) throws Exception {
String thisLine = null;
try {
// open input stream test.txt for reading purpose.
BufferedReader br = new BufferedReader("c:/test.txt");
while ((thisLine = br.readLine()) != null) {
System.out.println(thisLine);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
假设我们有一个文本文件c:/test.txt ,其内容如下。该文件将用作示例程序的输入-
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
让我们编译并运行以上程序,这将产生以下结果-
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz