Java program to read last line of a file
This program will output the last line of the file 'file.txt'
Re: How to Read the last line of a file
Hi,
I found there is another way of doing this.
Code :
RandomAccessFile rfile = new RandomAccessFile(file,"r");
rfile.seek(file.length());
Third One -
FileInputStream fis=new FileInputStream("D:\\ test\\sample.txt");
String fileContent = new Scanner(fis).useDelimiter("\\Z").next()
Source : Java : Quick way to read to get the last line from a File : "java" Category at Simply Share It
Re: How to Read the last line of a file
Yeah if you use the BufferedReader and you have a file which might be a couple of gigabyte in size, first of all your JVM will need a lot of memory and it will take you a while to do.
RandomAccess might be the better way to go.
// Json