|
How to use a random access file |
|
|
This Java tip illustrates a method of using random access files in an application.
Usually all the files permits sequential access. A random access files, on the other hand, permit nonsequential, or random, access to a file's contents.
try {
File f = new File("filename");
RandomAccessFile raf = new RandomAccessFile(f, "rw");
// Read a character
char ch = raf.readChar();
// Seek to end of file
raf.seek(f.length());
// Append to the end
raf.writeChars("aString");
raf.close();
} catch (IOException e) {
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.