Hey guys, im trying to generate matrix to store info from a txt file. My code reads every line from the file, counts the number of lines,
creates an array of that size. Then stores every line into a string array slot and splits each line by space character and creates another array of of it.
then by doing two "for" cycles i insert the information into my matrix. Im not sure if it works or how to test it. i could use some help fixing the code
and/or doing the same but with arraylists (i have no clue how to use them). I have to store information into a matrix the size of lines and then fill each column
with the number of elements i find in my file when spliting a line. If someone can think of an alternative way of procesing my files id Thanks!
PS: my nodos.txt file stores info as follows. Ex:
4
1 1
3 2
4 -3
EOF
public String[][] LectorNodos( ) throws IOException{ int LargoArchivo=0; String [] infoNodos; File HojaNodos=new File("nodos.txt"); String [][] matrizInfoNodos; String [] aux; if(HojaNodos.exists()){ Scanner lector = new Scanner(HojaNodos); while(lector.hasNext()){ lector.nextLine(); LargoArchivo++; } lector.close(); lector= new Scanner(HojaNodos); infoNodos = new String [LargoArchivo]; for(int i=0;i<infoNodos.length;i++){ infoNodos[i]=lector.nextLine(); } lector.close(); matrizInfoNodos=new String [LargoArchivo][3]; for(int k=0;k<infoNodos.length;k++){ aux=infoNodos[k].split("\\s+"); for(int j=0; j<aux.length;j++){ matrizInfoNodos[k][j]=aux[j]; } } for(int i=0;i<matrizInfoNodos.length;i++){ for(int j=0;j<matrizInfoNodos[0].length;j++){ Usuario.mensaje(matrizInfoNodos[i][j]); } } return matrizInfoNodos; } return null; }