Los CSVs son un formato de archivos muy utilizados para intercambio de datos. Básicamente son un fichero de texto en el que los campos están separados por comas.
En Java hay muchas librerías (ya hemos hablado de algunas) para leer Excels y CSVs.
En este post usan una forma mucho más sencilla 😀
| // CSVRead.java
//Reads a Comma Separated Value file and prints its contents. import java.io.*; import java.util.Arrays; public class CSVRead{ public static void main(String[] arg) throws Exception { int x, y, z; String name = "", race = ""; boolean hyperactive; BufferedReader CSVFile = new BufferedReader(new FileReader("Example.csv")); String dataRow = CSVFile.readLine(); // Read first line. // The while checks to see if the data is null. If // it is, we’ve hit the end of the file. If not, // process the data. while (dataRow != null){ String[] dataArray = dataRow.split(","); for (String item:dataArray) { System.out.print(item + "\t"); } System.out.println(); // Print the data line. dataRow = CSVFile.readLine(); // Read next line of data. } // Close the file once all data has been read. CSVFile.close(); // End the printout with a blank line. System.out.println(); } //main() } // CSVRead |

Deja un comentario