Difference between revisions of "Use a random access file"

From CodeCodex

 
(No difference)

Revision as of 15:13, 14 July 2006

Implementations

Java

    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) {
    }