实例如下
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();elses1.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 stubFileReader 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创建一个类实现读取一个文件中的每一行显示出来就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持VeVb武林网。
新闻热点
疑难解答
图片精选