-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReaderUtil.java
More file actions
39 lines (34 loc) · 1.13 KB
/
ReaderUtil.java
File metadata and controls
39 lines (34 loc) · 1.13 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class ReaderUtil {
public static List<String> getInputsStr(String path) {
try(BufferedReader br = new BufferedReader(new FileReader(path))) {
ArrayList<String> input = new ArrayList<>();
String line = br.readLine();
while (line != null) {
input.add(line);
line = br.readLine();
}
return input;
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<>();
}
}
public static List<Integer> getInputsInt(String path) {
try(BufferedReader br = new BufferedReader(new FileReader(path))) {
ArrayList<Integer> input = new ArrayList<>();
String line = br.readLine();
while (line != null) {
input.add(Integer.parseInt(line));
line = br.readLine();
}
return input;
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<>();
}
}
}