Tuesday, September 20, 2011

DELETE LAST LINE OF A FILE USING JAVA CODE




import java.io.*;


public class Test{
         public static void main(String[] rk){
             try{


             RandomAccessFile file= new RandomAccessFile("Data.txt", "rw");
             long length = file.length();


             System.out.println("File Length is ="+file.length());


             //Assume that last line is of 10 char 
             file.setLength(length - 10);


             System.out.println("Now File Length is ="+file.length());
             file.close();


             }catch(Exception ex){
 
  System.out.println("ERROE : "+ex);
         }
     }//end of psvm
}


Thank you


No comments:

Post a Comment