J'essaye d'obtenir un programme pour lire un fichier texte mais il lance une exception FileNotFoundException même si j'ai le fichier potato.txt dans le répertoire du projet.Lire un fichier en Java avec Scanner
import java.io.File;
import java.util.Scanner;
public static void main(String[] args) {
String potato = "potato.txt"; // assume this line can't be changed at all
Scanner scan = new Scanner(new File(potato)); // throws FileNotFoundException
while (scan.hasNextLine()) {
String line = scan.nextLine();
System.out.println(line);
}
}
}
Où est votre fichier exactement? – Carlton
Essayez d'utiliser le chemin absolu. – mdp
s'il vous plaît poster la structure du projet – Saravana