Commit 6856d0d3 authored by edmundszagars's avatar edmundszagars
Browse files

-Creating "GetDataFromCSV" class that will handle data collection from file

-Implementing method that wil output 2d array from CSV
parent 4003fb31
1, 2, 3, 4,
1, 2, 3,
\ No newline at end of file
1, 2, 3, 4
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
1, 2, 3
\ No newline at end of file
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class GetDataFromCSV {
private double[][] nDataArray;
//TODO: Make data array dynamic
public double[][] getDataFromCSV() {
nDataArray = new double[20][5];
Scanner scanner;
int cRow = 0;
String inputLine;
String nFileLocation = "data.csv";
try {
scanner = new Scanner(new BufferedReader(new FileReader(nFileLocation)));
while (scanner.hasNextLine()) {
inputLine = scanner.nextLine();
String[] inArray = inputLine.split(",");
for (int i = 0; i < inArray.length; i++) {
nDataArray[cRow][i] = Double.parseDouble(inArray[i]);
}
cRow++;
}
} catch (FileNotFoundException | ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}
return nDataArray;
}
}
public class Main {
public static void main(String[] args){
import java.io.FileNotFoundException;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
GetDataFromCSV get = new GetDataFromCSV();
double[][] resultArray = get.getDataFromCSV();
System.out.println(Arrays.deepToString(resultArray));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment