实例如下
java" id="highlighter_914208">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import java.io.*; import java.util.*; class MyBufferReaderDemo{ private FileReader fb; MyBufferReaderDemo(FileReader fb){ this .fb=fb; } public String BufferReader() throws IOException{ StringBuilder s1= new StringBuilder(); int ch= 0 ; while ((ch=fb.read())!=- 1 ) { if (ch== '\r' ) continue ; if (ch== '\n' ) return s1.toString(); else s1.append(( char )ch); } if (s1.length()!= 0 ) return s1.toString(); return null ; } public void myClose() throws IOException{ fb.close(); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub FileReader f1= new FileReader( "d:\\MyBufferReaderDemo.java" ); MyBufferReaderDemo myb= new MyBufferReaderDemo(f1); String line= null ; while ((line=myb.BufferReader())!= null ){ System.out.println(myb.BufferReader()); } myb.myClose(); } } |
以上这篇java创建一个类实现读取一个文件中的每一行显示出来就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。