-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.java
More file actions
42 lines (42 loc) · 684 Bytes
/
File.java
File metadata and controls
42 lines (42 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.*;
class File
{
String Prisoners[][];
char mode;
int num;
File()
{
Prisoners = new String[20][2]; // Stores information about prisoners
mode=' '; //Mode to make sure reading and writing are done separately
num=0; // Number of prisoners
}
void write(String data)
{
if(mode=='w')
{
Prisoners[num][0]=data.split(" ")[0]; //101 Arham Zaidi
Prisoners[num][1]=data.split(" ")[1]+" "+data.split(" ")[2];
num++;
}
else
{
mode = 'w'
write(data);
}
}
void read()
{
if(mode == 'r')
{
for(int i=0;i<num;i++)
{
System.out.println(Prisoners[i][0]+" "+Prisoners[i][1]);
}
}
else
{
mode = 'r';
read();
}
}
}