Code example for RandomAccessFile

Methods: close, readInt, seek, writeInt

0
    /** 
     * @tests java.io.RandomAccessFile#readInt() 
     */ 
    public void test_readInt() throws IOException { 
        // Test for method int java.io.RandomAccessFile.readInt() 
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
        raf.writeInt(Integer.MIN_VALUE);
        raf.seek(0);
        assertEquals("Incorrect int read/written", Integer.MIN_VALUE, raf
                .readInt());
        raf.close();
    } 
 
    /** 
     * @tests java.io.RandomAccessFile#readLine() 
     */ 
    public void test_readLine() throws IOException { 
        // Test for method java.lang.String java.io.RandomAccessFile.readLine() 
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
        String s = "Goodbye\nCruel\nWorld\n";
        raf.write(s.getBytes("UTF-8"), 0, s.length());