I need to get data from a CSV file and store it in an array.
Example:
CAIO ; 0909;abacaxi
BRUNO;1231;maça
I have to take for example line 1, and each value of each column store in a variable to play in a theft function (Selenium).
The way I managed to break csv, when I store for example usuarioDado[0]
in a variable and printo, I show all columns, however I wanted to get the first row of that column to store in a variable, then same thing with column 2, then in the end it would go to another line.
Finally, I need to store each value of the columns of the first row in an independent variable, and then do the same thing for row 2.
That's what I did:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
public class capturaDados {
private static final String VIRGULA = ";";
private static BufferedReader reader;
public static void main(String[] args) throws Exception {
try{
String arquivo = "C:\Users\rioscai\Documents\AcessosBKL.csv";
reader = new BufferedReader(new InputStreamReader(new FileInputStream(arquivo)));
String linha = null;
while ((linha = reader.readLine()) != null) {
String[] dadosUsuario = linha.split(VIRGULA);
System.out.println(Arrays.toString(dadosUsuario));
// System.out.println("Ambiente: " + dadosUsuario[0]);
/* System.out.println("Grupo: " + dadosUsuario[1]);
System.out.println("App: " + dadosUsuario[2]);
System.out.println("OBS: " + dadosUsuario[3]);
System.out.println("Perfil: " + dadosUsuario[4]);
System.out.println("--------------------------");*/
}
}catch(Exception e ){
e.printStackTrace();
}
}
}
Can anyone help?