31 public class ReadLine { |
31 public class ReadLine { |
32 |
32 |
33 public static void main(String args[]) throws Exception { |
33 public static void main(String args[]) throws Exception { |
34 File fn = new File("x.ReadLine"); |
34 File fn = new File("x.ReadLine"); |
35 RandomAccessFile raf = new RandomAccessFile(fn,"rw"); |
35 RandomAccessFile raf = new RandomAccessFile(fn,"rw"); |
36 String line; |
36 try { |
37 int ctr = 1; |
37 String line; |
38 String expected; |
38 int ctr = 1; |
|
39 String expected; |
39 |
40 |
40 raf.writeBytes |
41 raf.writeBytes |
41 ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14"); |
42 ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14"); |
42 raf.seek(0); |
43 raf.seek(0); |
43 |
44 |
44 while ((line=raf.readLine()) != null) { |
45 while ((line=raf.readLine()) != null) { |
45 if ((ctr == 7) || (ctr == 9) || |
46 if ((ctr == 7) || (ctr == 9) || |
46 (ctr == 11) || (ctr == 13)) { |
47 (ctr == 11) || (ctr == 13)) { |
47 expected = ""; |
48 expected = ""; |
48 } else { |
49 } else { |
49 expected = "ln" + ctr; |
50 expected = "ln" + ctr; |
|
51 } |
|
52 if (!line.equals(expected)) { |
|
53 throw new Exception("Expected \"" + expected + "\"" + |
|
54 ", read \"" + line + "\""); |
|
55 } |
|
56 ctr++; |
50 } |
57 } |
51 if (!line.equals(expected)) { |
58 } finally { |
52 throw new Exception("Expected \"" + expected + "\"" + |
59 raf.close(); |
53 ", read \"" + line + "\""); |
|
54 } |
|
55 ctr++; |
|
56 } |
60 } |
57 System.err.println("Successfully completed test!"); |
61 System.err.println("Successfully completed test!"); |
58 } |
62 } |
59 |
63 |
60 } |
64 } |