Skip to content

Instantly share code, notes, and snippets.

@Hikhuj
Last active November 6, 2018 20:43
Show Gist options
  • Save Hikhuj/651cf1495219b29b7da918f68cf7fc20 to your computer and use it in GitHub Desktop.
Save Hikhuj/651cf1495219b29b7da918f68cf7fc20 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package fundamentosproyectofinal;
import java.io.*;
import java.util.*;
/**
*
* @author rogerjoseulaterivera
*/
public class EscritorACsvJava {
// Variables
protected String pathDBUsuarios = "src/projectDatabase/usuarios.csv";
public static final String SEPARADOR = ",";
public void leerCSV() {
BufferedReader bufferLectura = null;
try {
// Abrir el .csv en buffer de lectura
bufferLectura = new BufferedReader(new FileReader(pathDBUsuarios));
// Leer una linea del archivo
String linea = bufferLectura.readLine();
while (linea != null) {
// Sepapar la linea leída con el separador definido previamente
String[] campos = linea.split(SEPARADOR);
System.out.println(Arrays.toString(campos));
for(int i = 0; i < campos.length; i++) {
for (int j = 0; j < campos[i].length(); j++) {
System.out.println(i);
}
}
// Volver a leer otra línea del fichero
linea = bufferLectura.readLine();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
// Cierro el buffer de lectura
if (bufferLectura != null) {
try {
bufferLectura.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment