I'm trying to store in an array the values of a file with the csv extension. This extension comes from a file made in excel, and when saved in this extension the values are separated by ";".
Throughthisimageyoucanalreadyimaginethefinalresultthatyouwouldliketoarrivewiththematrix.
Following,afterreadingthefile,followsmylogic:
1-BreaklinebylineofthisfileIread.
2-Storeeachrowinasinglevectorusingthesplitmethod,settingthedelimiter(";") as a parameter.
3 - Move from array to array.
The problem is that when I store row by row in vector, it stores only the last row I'm inserting.
(PrintNetBeansconsole)Thatis,insteadofaccumulatingthevaluesentered,itisoverlappingthevalueseachtimethesequencegoesdown.
Well,ifIcannotgetpastthispart,itisimpossibletostorethevaluesinsidethearray.And,please,IknowthereareothersolutionsinJavatofacilitatethisprocess.However,I'mreallytryingtoworkwithlogicandsimplefeaturestogetwhereIneedtogo.
So,mydifficultyistostoreeachvalueinthevectorusingthesplit()method.
Finally,followthecodeI'vealreadydone!
importjava.io.BufferedReader;importjava.io.FileInputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;publicclassEntradaSaidaIO{publicstaticvoidmain(Stringargs[])throwsIOException{Stringmatriz[][]=newString[26][26];//Matrizondecontém26linhase26colunasintn=26*26;//StringlinhaF[]=newString[n];//VetorondedeveriaarmazenarosvaloresdoarquivoInputStreame=newFileInputStream("C:\Users\Moraes\Desktop\MatrizApagar.csv");
InputStreamReader er = new InputStreamReader(e);
BufferedReader ebr = new BufferedReader(er);
String texto = ebr.readLine(); // O método readLine()apens lê uma linha do arquivo
while( texto != null){
System.out.println(texto);
linhaF = texto.split(";");
/*
for(int k = 0; k < linhaF.length; k++){
System.out.print(linhaF[k]); // Apenas exibe o conteúdo dentro do vetor linhaF
}
*/
texto = ebr.readLine();
}
for(int i = 0; i < linhaF.length; i++){
System.out.print(linhaF[i]); // Exibe todo o conteúdo armazenado
}
ebr.close();
}
}