Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > End of File

Reply
Thread Tools

End of File

 
 
Ken Kast
Guest
Posts: n/a
 
      04-18-2004
I have a character file off of which I'd like to eliminate the last n chars.
Put another way, when an app appends to the file I'd like it to append n
chars from the end, with the last n chars going to the great bit bucket in
the sky. Other than doing a read/write operation to eliminate the end of
the file, is there any simple way to move the EOF up n chars?

Thanks.

Ken


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-18-2004
On Sun, 18 Apr 2004 01:34:09 GMT, "Ken Kast" <(E-Mail Removed)>
wrote or quoted :

> Other than doing a read/write operation to eliminate the end of
>the file, is there any simple way to move the EOF up n chars?


There is in Windows using JNI. You open the file and do a 0-byte write
where you want to chop then close. When Ray Duncan first told me
about this I thought it was a joke. Otherwise, you have to copy up to
the place you want then delete and rename.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a
 
      04-18-2004
Ken Kast wrote:
> I have a character file off of which I'd like to eliminate the last n chars.
> Put another way, when an app appends to the file I'd like it to append n
> chars from the end, with the last n chars going to the great bit bucket in
> the sky. Other than doing a read/write operation to eliminate the end of
> the file, is there any simple way to move the EOF up n chars?
>
> Thanks.
>
> Ken
>
>


I think you need to look at RandomAccessFile, which will allow you to seek
to n bytes from the end.

Steve
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      04-19-2004
Steve Horsley wrote:

>> I have a character file off of which I'd like to eliminate the last n
>> chars.
>> Put another way, when an app appends to the file I'd like it to append n
>> chars from the end, with the last n chars going to the great bit
>> bucket in
>> the sky. Other than doing a read/write operation to eliminate the
>> end of
>> the file, is there any simple way to move the EOF up n chars?

>
> I think you need to look at RandomAccessFile, which will allow you to seek
> to n bytes from the end.


And also to shorten the file, which I think is what he actually wants to do.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-19-2004
On Mon, 19 Apr 2004 12:04:19 +0200, Michael Borgwardt
<(E-Mail Removed)> wrote or quoted :

>And also to shorten the file, which I think is what he actually wants to do.


RandomAccessFile.setLength. Never noticed that before.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
mromarkhan@rogers.com
Guest
Posts: n/a
 
      04-20-2004

import java.io.*;
public class JamEOF
{
RandomAccessFile rf;
File f;
public JamEOF() throws IOException
{
f = new File("c:\\windows\\desktop\\test.txt");
rf = new RandomAccessFile(f , "rw");
System.out.println("Before update: "+rf.length());
long n=56;
rf.setLength(rf.length() - n);
System.out.println("After update: "+rf.length());
rf.close();
}

public static void main(String [] args) throws IOException
{
new JamEOF();
}
}

Have a good day.
Peace.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 13 09-21-2011 12:17 AM
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 3 09-09-2011 10:36 PM
Help with switch configuration, ( 3 3550's, 5 2950's end to end ) ec Cisco 3 07-25-2006 10:30 AM
Measure delay end-to-end Dave Cisco 1 07-20-2004 12:51 PM
is there a difference between CIR and CIR+end to end clear channel connection? ike lozada Cisco 0 05-27-2004 02:34 AM



Advertisments