Thursday 22 September 2016

Java Tutorial : Java IO (LineNumberReader)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=KKV54H9cMu0&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java IO (LineNumberReader) 
Java Tutorial : Java IO (LineNumberReader) 
Java Tutorial : Java IO (LineNumberReader) 
myfile.txt
Welcome
Hello
Bye
LineNumberReaderDemo.java
import java.io.FileReader;
import java.io.LineNumberReader;

public class LineNumberReaderDemo
{

    public static void main(String[] args) throws Exception
    {
        LineNumberReader lineNumberReader = null;
        FileReader fileReader = null;
        try
        {
            fileReader = new FileReader("myfile.txt");
            lineNumberReader = new LineNumberReader(fileReader);

            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();
            }
        }
    }
}
Output
1 = Welcome
2 = Hello
3 = Bye
Refer:
https://docs.oracle.com/javase/8/docs/api/index.html?java/io/LineNumberReader.html
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_LineNumberReaderDemo_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_LineNumberReaderDemo_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8270b2c7cbb37f975ee9fc66e47a041db3aa4063/BasicJava/JavaIODemo_LineNumberReaderDemo_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment