forked from gihanjayatilaka/Motify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayFileHandling.java
28 lines (26 loc) · 1.1 KB
/
ArrayFileHandling.java
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
//Testing Git
import java.io.*;
import java.util.ArrayList;
public class ArrayFileHandling {
public static void saveArrayCustomName(ArrayList<Reminder> arrayToSave,String fileName) throws Exception{
FileOutputStream fos=new FileOutputStream(fileName);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeInt(arrayToSave.size());
for(int x=0;x<arrayToSave.size();x++) oos.writeObject(arrayToSave.get(x));
}
public static ArrayList<Reminder> readArrayCustomName(String fileName) throws Exception{
FileInputStream fis=new FileInputStream(fileName);
ObjectInputStream ois=new ObjectInputStream(fis);
int noOfReminders=ois.readInt();
ArrayList<Reminder> arrayRead=new ArrayList<Reminder>();
for(int x=0;x<noOfReminders;x++) arrayRead.add((Reminder)ois.readObject());
arrayRead=ArrayHandling.sortReminders(arrayRead);
return arrayRead;
}
public static void saveArray(ArrayList<Reminder> arrayToSave) throws Exception{
saveArrayCustomName(arrayToSave,"database.dat");
}
public static ArrayList<Reminder> readArray() throws Exception{
return readArrayCustomName("database.dat");
}
}