FileDocCategorySizeDatePackage
ReadRandom.javaAPI DocExample1185Sun Mar 07 11:30:36 GMT 2004None

RandomRead

public class RandomRead extends Object
Read a file containing an offset, and a String at that offset.
author
Ian F. Darwin, http://www.darwinsys.com/
version
$Id: ReadRandom.java,v 1.6 2004/03/07 17:30:35 ian Exp $

Fields Summary
static final String
FILENAME
protected String
fileName
protected RandomAccessFile
seeker
Constructors Summary
public RandomRead(String fname)
Constructor: save filename, construct RandomAccessFile

		fileName = fname;
		seeker = new RandomAccessFile(fname, "r");
	
Methods Summary
public static voidmain(java.lang.String[] argv)


	       
		RandomRead r = new RandomRead(FILENAME);

		System.out.println("Offset is " + r.readOffset());
		System.out.println("Message is \"" + r.readMessage() + "\".");
	
public java.lang.StringreadMessage()
Read the message at the given offset

		seeker.seek(readOffset());	// move to the offset
		return seeker.readLine();	// and read the String
	
public intreadOffset()
Read the Offset field, defined to be at location 0 in the file.

		seeker.seek(0);				// move to very beginning
		return seeker.readInt();	// and read the offset