Very beginner to java. My program prints just a long column instead of a 2d array. For testing I use a file with 10 lines and 20 columns, but the actual file will be 20 columns and a few thousands lines, I don't know how many. I've read all the posts I could find on the internet on this topic but still couldn't get the program to work. Any ideas?
1 2 4 6 9 13 15 16 21 28 34 37 41 48 50 52 53 54 57 68
6 7 10 17 23 24 27 28 31 39 42 43 46 48 50 55 60 61 67 70
2 3 5 7 11 14 15 20 28 45 46 47 48 52 56 61 62 63 66 70
4 5 7 11 13 15 19 23 24 27 28 35 38 40 48 50 57 58 64 66
3 8 20 26 27 32 36 38 39 43 45 47 50 53 54 56 59 61 67 68
1 3 5 7 15 19 26 30 31 36 41 44 48 49 56 58 59 60 61 65
1 2 4 6 9 13 15 16 21 28 34 37 41 48 50 52 53 54 57 68
6 7 10 17 23 24 27 28 31 39 42 43 46 48 50 55 60 61 67 70
2 3 5 7 11 14 15 20 28 45 46 47 48 52 56 61 62 63 66 70
4 5 7 11 13 15 19 23 24 27 28 35 38 40 48 50 57 58 64 66
Here is the code
try {
FileInputStream fstream = new FileInputStream("C:\\keno.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = "";
String[] tokens;
//Read File Line By Line
int row = 0;
String userdata [][]= new String [10][21];
while ((strLine = br.readLine()) != null) {
// Copy the content into the array
tokens = strLine.split(" +");
for(int j = 0; j < tokens.length; j++) {
userdata[row][j] = tokens[j];
}
row++;
}
for(int i = 0; i < userdata.length; i++) {
for(int j=0; j < userdata[i].length; j++){
System.out.println(userdata[i][j]);
}
}
in.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}