题目:文件的路径:D:\file\test.data ,是字节数据,读取该文件并按行输出内容;
class="java" name="code">
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test11 {
public static void main(String[] args){
InputStreamReader isr;
try {
isr = new InputStreamReader(new FileInputStream("test.txt"));
BufferedReader br = new BufferedReader(isr);
String buff = null;
while ((buff=br.readLine()) != null) {
System.out.println(buff);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
输出:
静夜思
窗前明月光;
地上鞋两双。