FileDocCategorySizeDatePackage
RandomRead.javaAPI DocExample1172Tue Mar 13 15:32:32 GMT 2001None

RandomRead

public class RandomRead extends Object
Read a file containing an offset, and a String at that offset.
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: RandomRead.java,v 1.4 2001/03/13 20:32:33 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 where
		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