-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomAccess.java
More file actions
21 lines (19 loc) · 793 Bytes
/
RandomAccess.java
File metadata and controls
21 lines (19 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package stream;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RandomFile {
public static void main(String[] args) throws IOException {
RandomAccessFile rf = new RandomAccessFile("C:\\MyJava\\Access.txt","rw");
//byte b[]={'A','B','C','D','E','F','G','H','I','J'};
System.out.println((char) rf.read());// After printing pointer moves to next index
System.out.println((char) rf.read());
System.out.println((char) rf.read());
System.out.println((char) rf.read());
rf.write('e');
rf.seek(4); // got any index[]
System.out.println((char) rf.read());
System.out.println(rf.getFilePointer());
// get the location of pointer
System.out.println((char) rf.read());
}
}