Repository navigation
Expand file tree
/
Copy pathBeanDataFileRead.java
More file actions
67 lines (49 loc) · 1.56 KB
/
Copy pathBeanDataFileRead.java
File metadata and controls
67 lines (49 loc) · 1.56 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gnnbeanfix;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class BeanDataFileRead {
private static int noOfDimensions = 8;
public static ArrayList<ArrayList<Double>> readValues(String filename){
ArrayList<ArrayList<Double>> values = new ArrayList<ArrayList<Double>>();
// create the array lists
for(int x = 0; x < noOfDimensions; x++)
values.add(new ArrayList<Double>());
Scanner s;
try {
s = new Scanner(new BufferedReader(new FileReader(filename)));
s.nextLine();
while (s.hasNext()) {
for(ArrayList<Double> list : values)
list.add(s.nextDouble());
// skip the classification
s.next();
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return values;
}
public static ArrayList<String> readClassifications(String filename){
ArrayList<String> classification = new ArrayList<String>();
Scanner s;
try {
s = new Scanner(new BufferedReader(new FileReader(filename)));
s.nextLine(); // skips column titles
while (s.hasNext()) {
// skip the double values
for(int x = 0; x < noOfDimensions; x++)
s.nextDouble();
// read in the classification
classification.add(s.next());
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return classification;
}
}