Package ioTest. io2;/** customize a decoration class for reading files with the method of reading row numbers */import java. io. fileReader; import java. io. IOException; import java. io. reader; public class MyLineNumberReaderDemo {public static void main (String [] args) throws IOException {String line; // create an input stream-Read File Information to the central stream, therefore, for the stream, FileReader in = new FileReader ("BufferedWriterDemo. java "); MyLineNumberReader mlnr = new MyLineNumberReader (in); while (line = mlnr. myReadLine ())! = Null) {System. out. println (mlnr. getLineNumber () + ":" + line);} mlnr. close () ;}// define a custom class similar to LineNumberReader MyLineNumberReader extends Reader {private Reader r; int lineNumber; int ch = 0; String line = null; // judging from the constructor, it is clear that this class is also a constructor class MyLineNumberReader (Reader r) {this. r = r;} public String MyReadLine () throws IOException {lineNumber ++; StringBuilder sBuilder = new StringBuilder (); while (ch = r. read ())! =-1) {if (ch = '\ n') continue; if (ch =' \ R') return sBuilder. toString (); elsesBuilder. append (char) ch);} if (sBuilder. length ()> 0) return sBuilder. toString (); return null;} public int getLineNumber () {return lineNumber;} public void setLineNumber (int lineNumber) {this. lineNumber = lineNumber;} @ Overridepublic int read (char [] cbuf, int off, int len) throws IOException {// TODO Auto-generated method stubreturn 0 ;} @ Overridepublic void close () throws IOException {// TODO Auto-generated method stubr. close ();}}