-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase
More file actions
46 lines (41 loc) · 1.18 KB
/
Database
File metadata and controls
46 lines (41 loc) · 1.18 KB
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
43
44
45
46
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
public class Database {
private static final int MAX_FILE=100;
private FileWritable[] list = new FileWritable[MAX_FILE];
public Database(){
}
public void addDatabase(FileWritable row){
for(int i=0;i<list.length;i++){
if(list[i]!=null){
list[i++]=row;
break;
}
}
}
public void removeDatabase(FileWritable row){
for(int i=0;i<list.length;i++){
if(row.equals(list[i])){
list[i]=null;
}
}
}
public void writeAll(String filename){
try(BufferedWriter bw=new BufferedWriter(new FileWriter("text.txt"))){
for (FileWritable row:list){
if(row!=null){
row.writeToFile(bw);
}
}
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args){
Database database=new Database();
database.addDatabase(new Student("apple",123));
database.writeAll("text.txt");
}
}