Click here to watch in Youtube :
https://www.youtube.com/watch?v=J2V7ttOFDuQ&list=UUhwKlOVR041tngjerWxVccw
myfile.txt
Welcome Hello Bye
import java.io.FileReader; import java.io.LineNumberReader; /* * public LineNumberReader(Reader in, int sz) * * Parameters: * ---------- * * in - A Reader object to provide the underlying stream. * sz - An int specifying the size of the buffer. */ public class LineNumberReaderDemo { public static void main(String[] args) throws Exception { LineNumberReader lineNumberReader = null; FileReader fileReader = null; try { int bufferSize = 1024; fileReader = new FileReader("myfile.txt"); /* * Create a new line-numbering reader, reading * characters into a buffer of the given size. */ lineNumberReader = new LineNumberReader(fileReader, bufferSize); String line; while ((line = lineNumberReader.readLine()) != null) { int lineNumber = lineNumberReader.getLineNumber(); System.out.println(lineNumber + "." + line); } } finally { if (lineNumberReader != null) { /* * When you are finished reading characters * from the LineNumberReader you should * remember to close it. Closing a * LineNumberReader will also close the * Reader instance from which the * LineNumberReader is reading. */ lineNumberReader.close(); } } } }
1.Welcome 2.Hello 3.Bye
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_LineNumberReaderDemo_Cons_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_LineNumberReaderDemo_Cons_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8270b2c7cbb37f975ee9fc66e47a041db3aa4063/BasicJava/JavaIODemo_LineNumberReaderDemo_Cons_App/?at=master
See also:
No comments:
Post a Comment