Boujour,
Je veux pouvoir lire un fichier csv, mais voila, l'exception FileNotFoundException remonte toujours, alors que le fichier existe bien. Etant debutant en java, pourais avoir plus d'info concernant le chemin d'acces au fichier?
Voici le code utiliser pour parser le .csv (j'utilise Eclipse):
(dans mon cas, path = "D:/test.csv"
fichier en lecture et ecriture )
public void parseFile(String path) throws FileNotFoundException, IOException {
File csvFile = new File(path);
if (!csvFile.exists())
throw new FileNotFoundException("Le fichier n'existe pas");
if (csvFile.isDirectory())
throw new FileNotFoundException("Le chemin désigne un répertoire et non un fichier");
if (!csvFile.getAbsolutePath().endsWith(".csv"))
throw new FileNotFoundException("Le fichier n'est pas du type CSV (Comma Separated Value)");
StringTokenizer lineParser;
BufferedReader reader = new BufferedReader(new FileReader(csvFile));
dataTable = new ArrayList<ArrayList>();
ArrayList<String> dataRow;
String line = null;
String value = null;
while ((line = reader.readLine()) != null) {
dataRow = new ArrayList<String>();
lineParser = new StringTokenizer(line, ",");
while (lineParser.hasMoreElements()) {
value = (String) lineParser.nextElement();
dataRow.add(value);
}
dataTable.add(dataRow);
}
}
public ArrayList<ArrayList> getDataList() {
return dataTable;
}
Merci pour votre aide !!!
Configuration: Windows XP
Internet Explorer 6.0