/
ReadIntegerFromFile.java
52 lines (43 loc) · 1.63 KB
/
ReadIntegerFromFile.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
48
49
50
51
52
package stack.overflow.test.two;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
/**
* Created by Pankaj Nimgade on 11-02-2016.
*/
public class ReadIntegerFromFile {
public static void main(String[] args) {
int[] force_l = null;
int[] force_r = null;
try {
File file = new File("file_json_test_three.txt");
Path path = file.toPath();
List<String> strings = Files.readAllLines(path);
//List<String> strings = FileUtils.readLines(file); can be used with common-io-2.4 library
int count = 0;
for (String s : strings) {
//System.out.println(s);
String[] integer_Strings = s.split(" ");
//System.out.println(Arrays.deepToString(integer_Strings));
if (count == 0) {
force_l = new int[integer_Strings.length];
for (int i = 0; i < integer_Strings.length; i++) {
force_l[i] = Integer.parseInt(integer_Strings[i]);
}
count++;
} else if (count == 1) {
force_r = new int[integer_Strings.length];
for (int i = 0; i < integer_Strings.length; i++) {
force_r[i] = Integer.parseInt(integer_Strings[i]);
}
}
}
System.out.println(Arrays.toString(force_l));
System.out.println(Arrays.toString(force_r));
} catch (Exception e) {
e.printStackTrace();
}
}
}