Array now initialized with correct size
I still don't know how to put the csv into the array tough
This commit is contained in:
parent
4ac94f9ce1
commit
b16d900532
@ -4,32 +4,39 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Matrix {
|
public class Matrix {
|
||||||
private String[] result;
|
private String[][] matrix;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] importCSV(String file) {
|
public String[][] importCSV(String file) {
|
||||||
result = new String[100];
|
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
||||||
String line;
|
String line = br.readLine();
|
||||||
try {
|
int rowCount = 0;
|
||||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
int columnCount = line.split(";").length;
|
||||||
|
|
||||||
while ((line = br.readLine()) != null) {
|
while (line != null) {
|
||||||
result = line.trim().split(";");
|
line = br.readLine();
|
||||||
|
rowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matrix = new String[rowCount][columnCount];
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return result;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printCSV() {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,6 @@ public class TestMatrix {
|
|||||||
Matrix m = new Matrix();
|
Matrix m = new Matrix();
|
||||||
|
|
||||||
m.importCSV("/home/satan/bin/graphprogram/graph.csv");
|
m.importCSV("/home/satan/bin/graphprogram/graph.csv");
|
||||||
System.out.println(m);
|
m.printCSV();;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user