Java > Core Java
Remove last line from file
Remove last line from file import java.io.*; public class DelLstLine{ public static void main(String[] arg){ try{ RandomAccessFile raf = new RandomAccessFile("RandFile.txt", "rw"); long length = raf.length(); System.out.println("File Length="+raf.length()); //supposing that last line is of 8 raf.setLength(length - 8); System.out.println("File Length="+raf.length()); raf.close(); }catch(Exception ex){ ex.printStackTrace(); } }//end of psvm }//class ends
Java Codes
Beginners
Core Java
Date Time
Java2D
Java Applets
Java AWT
Mathematics
Networking
Servlets
Session
Sound
Swing
Threads
Util Package
JDBC
Learning
Other
Security
XML