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

Advertisements

About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in J2SE. Bookmark the permalink.

2 Responses to DELETE LAST LINE OF A FILE USING JAVA CODE

  1. random says:

    This would not really work because length of the file is not determined by how many characters it has

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s