-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadFromFile.java
28 lines (26 loc) · 963 Bytes
/
ReadFromFile.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
package contacts_list;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
public class ReadFromFile implements Serializable {
public static ArrayList<Contact> read(){
ArrayList<Contact> list = new ArrayList<>();
try{
FileReader fr = new FileReader("contacts.txt");
BufferedReader br = new BufferedReader(fr);
String line;
while ((line = br.readLine()) != null){
String[] pieces = line.split("\t");
String[] namePieces = pieces[0].split(" ");
Contact c = new Contact(namePieces[0], namePieces[1], pieces[1], pieces[2], pieces[3], pieces[4]);
list.add(c);
}
}
catch (IOException e){
System.out.println("Olvasási hiba történt.");
}
return list;
}
}