|
|
You are here:
Home >
All Posts
> N/A
> Wipro
> technical
Java : Quick way to read to get the last line from a File
There are different ways to achieve this - First One - try { File f = new File("data.txt"); FileInputStream fis = new FileInputStream(f); byte[] content = new byte[fis.available()]; fis.read(content); String data = new String(content);
String[] split = data.split(System.getProperty("line.separator")); String lastLine = ""; if(split.length > 0){ lastLine = split[split.length -1]; } System.out.println(lastLine); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Second One -
Third One -
FileInputStream fis=new FileInputStream("D:\\ test\\sample.txt");
String fileContent = new Scanner(fis).useDelimiter("\\Z").next(); ![]() Comments
|
Related Posts
View All
Posts by Ankit
View All
Tags :
|
|||
|
About Us |
Contact Us |
Privacy Policy |
Terms of Use |
Getting Started |
FAQ |
Media Coverage
© 2009 Copyrights. All Rights Reserved. |
|||||

HOME
ALL POSTS
ADD NEW POST
MY POSTS
HOUSING
VEHICLES & HOUSE HOLD
TECHNICAL
JOBS
OTHERS


