aspose file tools*
The moose likes I/O and Streams and the fly likes Reading files from the end Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading files from the end " Watch "Reading files from the end " New topic
Author

Reading files from the end

Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 104

Hello,

Hello,

I have to read 2 fields which are located at the end of a text file.

Is there any way to do that without reading the complete file?

Is it possible to start reading a file from the end and finish on top?

Many thanks.

<field>
<field>
<.....>
<.....>
<field to read>
<filed to read>
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8924
    
    9

java.io.RandomAccessFile


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 104

I think that RandomAccessFile would be usefull if I knew the size or structure of the fileds,

but I dont know anything about the fields except their names.

My Idea was to begin reading at botton of the file and climb over the file because I these fields are always at the botton.

How do you would use RandonAccess field class in that case?

Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8924
    
    9

Get the length of the file, set the file pointer to the end of the file, read a byte, back up one, read a byte, and so on.
Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 104

OK, I´m going to try it...

Thans.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading files from the end