4 public class RandomAccessFileTest
{
5 public static void main (String args
[]) {
7 File f
= new File("/etc/passwd");
8 RandomAccessFile rf
= new RandomAccessFile(f
,"r");
10 long length
= rf
.length();
13 long pos
= rf
.getFilePointer();
15 if ( (length
- 10) != pos
)
16 throw new Exception("Bad value from getFilePointer(), " +
17 pos
+ " !=" + (length
- 10));
20 byte b
= rf
.readByte();
21 boolean test
= rf
.readBoolean();
23 byte buf
[] = new byte[40];
30 throw new Exception("Got length from closed RandomAccessFile().");
31 } catch (IOException e
) {}
33 String filename2
= "/var/tmp/testfile-remove";
35 File f2
= new File(filename2
);
36 RandomAccessFile rf2
= new RandomAccessFile(filename2
, "rw");
44 System
.out
.println("PASSED: RandomAccessFile worked.");
46 } catch (Exception e
) {
47 System
.out
.println("FAILED: "+e
);