Code example for RandomAccessFile

Methods: close, readBoolean, seek, writeBoolean

0
    /** 
     * @tests java.io.RandomAccessFile#readBoolean() 
     */ 
    public void test_readBoolean() throws IOException { 
        // Test for method boolean java.io.RandomAccessFile.readBoolean() 
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
        raf.writeBoolean(true);
        raf.seek(0);
        assertTrue("Incorrect boolean read/written", raf.readBoolean());
        raf.close();
    } 
 
    /** 
     * @tests java.io.RandomAccessFile#readByte() 
     */ 
    public void test_readByte() throws IOException { 
        // Test for method byte java.io.RandomAccessFile.readByte() 
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
        raf.writeByte(127);
        raf.seek(0);
        assertEquals("Incorrect bytes read/written", 127, raf.readByte());