-
Notifications
You must be signed in to change notification settings - Fork 0
/
IO.java
47 lines (38 loc) · 1.27 KB
/
IO.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package realestateapp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
public class IO{
@SuppressWarnings("unchecked")
public ArrayList<RealEstate> fileReader() throws ClassNotFoundException, IOException {
ArrayList<RealEstate> arraylist = new ArrayList<RealEstate>();
try {
File file = new File("D:\\Eclipse\\RealEstate\\Ads.txt");
if (file.length() == 0) {
arraylist = new ArrayList<RealEstate>();
} else {
FileInputStream fis = new FileInputStream("D:\\Eclipse\\RealEstate\\Ads.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
arraylist = (ArrayList<RealEstate>) ois.readObject();
ois.close();
fis.close();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return arraylist;
}
// File Writer Method
public void fileWriter(ArrayList<RealEstate> arr) throws IOException {
FileOutputStream fos = new FileOutputStream("D:\\Eclipse\\RealEstate\\Ads.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(arr);
oos.close();
fos.close();
}
}