-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataToARFF.java
More file actions
58 lines (47 loc) · 1.26 KB
/
DataToARFF.java
File metadata and controls
58 lines (47 loc) · 1.26 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
public class DataToARFF
{
public String[] attributes;
public String[][] data;
public static void main (String[] args)
{
}
private void readData(String filename)
{
ArrayList<String[]> list = new ArrayList<String[]>(); // list to store the incoming data
try{
//Read the input file and convert to 2d array
File inFile = new File(filename);
if (inFile.isFile()) {
// create BufferedReader and read data from csv
BufferedReader csvReader = new BufferedReader(new FileReader(filename));
String row;
while ((row = csvReader.readLine()) != null) {
String[] data = row.split(",");
int[] tmp = new int[3];
//convert String[] to int[]
for(int i=0; i<3; i++)
{
tmp[i] = Integer.parseInt(data[i]);
}
//add the int[] to the ArrayList
list.add(tmp);
}
//finally, close the reader
csvReader.close();
}
}
catch(Exception e)
{
System.out.println("Failed to parse file. Please check file format.");
System.exit(1);
}
}
private void writeARFF()
{
}
}