Completed reading in the CSV #1

Merged
AustrianToast merged 12 commits from Feature/import_csv into dev 2023-03-17 15:31:57 +01:00
2 changed files with 20 additions and 13 deletions
Showing only changes of commit b16d900532 - Show all commits

View File

@ -4,32 +4,39 @@ import java.io.FileReader;
import java.io.IOException;
public class Matrix {
private String[] result;
private String[][] matrix;
public static void main(String[] args) {
}
public String[] importCSV(String file) {
result = new String[100];
String line;
try {
BufferedReader br = new BufferedReader(new FileReader(file));
public String[][] importCSV(String file) {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line = br.readLine();
int rowCount = 0;
int columnCount = line.split(";").length;
while ((line = br.readLine()) != null) {
result = line.trim().split(";");
while (line != null) {
line = br.readLine();
rowCount++;
}
matrix = new String[rowCount][columnCount];
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
return matrix;
}
public void printCSV() {
for(int i=0; i < matrix.length; i++) {
for(int j=0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j]);
}
System.out.println();
}
}
}

View File

@ -7,6 +7,6 @@ public class TestMatrix {
Matrix m = new Matrix();
m.importCSV("/home/satan/bin/graphprogram/graph.csv");
System.out.println(m);
m.printCSV();;
}
}