RandomReadpublic class RandomRead extends Object Read a file containing an offset, and a String at that offset. |
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 void | main(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.String | readMessage()Read the message at the given offset
seeker.seek(readOffset()); // move to the offset
return seeker.readLine(); // and read the String
| public int | readOffset()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
|
|