















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















Accessing a specific file using
sequential access
On an average, we have to read half of the zip archive to find the required file
RandomAccessFile(File file, String mode) Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument. RandomAccessFile(String name, String mode) Creates a random access file stream to read from, and optionally to write to, a file with the specified name.
f.seek(n);
long n = f.getFilePointer();
long filelength = f.length();
// set pointer to the beginning of file and read next two items myfile.seek(0); System.out.println (myfile.readInt()); System.out.println
(myfile.readDouble()); //set pointer to the 4th item and read it myfile.seek(16); System.out.println
(myfile.readBoolean()); // Go to the end and “append”
an integer 2003 myfile.seek(myfile.length()); myfile.writeInt(2003); // read 5th and 6th items myfile.seek(17); System.out.printlna
Int
Double
Int boolean Char Int
0
4
12
16 17 19
23