Code example for RandomAccessFile

Methods: closereadUnsignedByteseekwriteByte

0
 
    /** 
     * java.io.RandomAccessFile#readUnsignedByte() 
     */ 
    public void test_readUnsignedByte() throws IOException { 
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
        raf.writeByte(-1);
        raf.seek(0);
 
        assertEquals("Test 1: Incorrect value written or read;",
                255, raf.readUnsignedByte());
 
        try { 
            raf.readUnsignedByte();
            fail("Test 2: EOFException expected.");
        } catch (EOFException e) {
            // Expected. 
        } 
 
        raf.close();
        try { 
            raf.readUnsignedByte();
            fail("Test 3: IOException expected.");
        } catch (IOException e) {
            // Expected. 
        } 
    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE