This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 102

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: 8713
    
    6

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: 102

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: 8713
    
    6

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: 102

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
 
Similar Threads
CMP beans not entering data in database
Could not Create entity error.
won't create tables with jaws.xml
EJB 2.1 CMP Automatic primary key issue with <unknown-primary-key-field>empId</unknown-primary-key-f
If Sun's DB interface returns String[], Is Value Object needed?