-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read.java
40 lines (34 loc) · 1.28 KB
/
Read.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
package New;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Read {
public static ArrayList<String[]> ReadFromFile(String GivenBday) {
try {
File myObj = new File("clientList.txt");
Scanner myReader = new Scanner(myObj);
ArrayList<String[]> personalData = new ArrayList<String[]>();
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
String[] array1 = SplitToArray(data);
if (!array1[0].equals("Official")) {
String Bdate = array1[array1.length - 1];
if (Bdate.split("/", 2)[1].equals(GivenBday.split("/", 2)[1])) {
personalData.add(array1);
}
}
}
myReader.close(); // Close the scanner after reading the file
return personalData;
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return null;
}
public static String[] SplitToArray(String str) {
String[] arrOfStr = str.split(",");
return arrOfStr;
}
}