1
I need to take 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 row 1, and each value of each column store in a variable to play in a robot 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, but I wanted to take the first row of this column to store in a variable, then same thing with column 2, then at the end I would go to another row.
Anyway, I need to store each value of the first row columns 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();
}
}
}
Anyone can help?
Caio, edit your question and include the code you made. This helps anyone who helps you.
– StatelessDev
Tomorrow I will post , because this on the work PC
– Caio Sousa