I'm trying to work on a csv file with Java.
After a split, I would like to work on the first column of the file.
But when I print my variable (cities = dataContent[0]) I still have all the file in the console.
package klm.java.controlFile;
import java.io.*;
public class ControleCSV {
public static void main(String[] args) {
try{
FileReader fr = new FileReader("communes_avec_erreurs.csv");
BufferedReader br = new BufferedReader(fr);
String dataContent[];
String cities;
StringBuilder lsbContenu = new StringBuilder();
String lsLigne;
while ((lsLigne = br.readLine()) != null) {
dataContent = lsLigne.split(";");
for(int i = 0; i < dataContent.length; i++){
lsbContenu.append(dataContent[i]);
lsbContenu.append("\n");
cities = dataContent[0];
System.out.println(cities);
}
}
br.close();
fr.close();
// System.out.println(lsbContenu.toString());
} catch (FileNotFoundException e) {
System.err.println("Erreur de fichier : " + e.getMessage());
} catch (IOException e) {
System.err.println("Erreur de lecture : " + e.getMessage());
}
}
}
cities = dataContent[0];tocities = dataContent[i];cities = dataContent[i];would print the whole file non ?','or something else than';'?