PR target/27599
[official-gcc.git] / libjava / classpath / testsuite / java.io / RandomAccessFileTest.java
blob69dc4383cad5dea5efbe01a1e9908a0244c610f4
2 import java.io.*;
4 public class RandomAccessFileTest {
5 public static void main (String args[]) {
6 try {
7 File f = new File("/etc/passwd");
8 RandomAccessFile rf = new RandomAccessFile(f,"r");
10 long length = rf.length();
12 rf.seek(length - 10);
13 long pos = rf.getFilePointer();
15 if ( (length - 10) != pos )
16 throw new Exception("Bad value from getFilePointer(), " +
17 pos + " !=" + (length - 10));
19 int i = rf.read();
20 byte b = rf.readByte();
21 boolean test = rf.readBoolean();
23 byte buf[] = new byte[40];
24 rf.seek(0);
25 rf.read(buf);
27 rf.close();
28 try {
29 length = rf.length();
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");
38 rf2.write(100);
39 rf2.write(buf);
41 rf2.close();
42 f2.delete();
44 System.out.println("PASSED: RandomAccessFile worked.");
45 System.exit(0);
46 } catch (Exception e) {
47 System.out.println("FAILED: "+e);