Code example for RandomAccessFile

Methods: closereadByteseekwriteByte

0
    /** 
     * @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());
        raf.close();
    } 
 
    /** 
     * @tests java.io.RandomAccessFile#readChar() 
     */ 
    public void test_readChar() throws IOException { 
        // Test for method char java.io.RandomAccessFile.readChar() 
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
        raf.writeChar('T');
        raf.seek(0);
Experience pair programming with AI  Get Codota for Java