Skip to content

Commit ad38991

Browse files
authored
Create RandomAccessFileEx.java
1 parent 2317de6 commit ad38991

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

io/RandomAccessFileEx.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.zetcode;
2+
3+
import java.io.IOException;
4+
import java.io.RandomAccessFile;
5+
6+
// RandomAccessFile allows to directly manipulate
7+
// the contents of a file
8+
public class RandomAccessFileEx {
9+
10+
public static void main(String[] args) throws IOException {
11+
12+
try (var raf = new RandomAccessFile("test.txt", "rw")) {
13+
14+
raf.writeBytes("golden ring");
15+
16+
raf.seek(0);
17+
System.out.println(raf.readLine());
18+
19+
raf.seek(7);
20+
raf.writeBytes("eagle");
21+
22+
raf.seek(0);
23+
System.out.println(raf.readLine());
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)