In This Tutorial we want to describe you a code that helps you in understanding Get Last Line of File in Java . For this we have a class name "Get Last Line of File". Inside the main method we create an instance of file class by using a new operator and passing a text .txt as a argument.
1)Input Stream Reader - This is used to read the byte and decode it into character stream from the text.txt present in a file.
2)Buffered Reader- This is used to read the character stream from the text.txt present in stream reader.
We declare a String object name line using new string operator.
3)file.getname( )-This method return you the name of the file printed by System.out.println.
While loop evaluate the condition weather the stream is ready to read
4)br.readline( )-This method is used to read the whole line of the Text.txt and store in line object of string class, that is further printed by System.out.println.
Finally the last line of file is printed by the System.out.println.
GetLastLineOfFile.java
import java.io.*;
|
text.txt
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java Get Last Line of File View All Comments
Post your Comment