Sto usando Eclipse per compilare ed eseguire i miei codici java.Eccezione nel thread "main" java.io.FileNotFoundException: Errore
Ecco l'errore che sto ottenendo.
Exception in thread "main" java.io.FileNotFoundException: file.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at helloworld.main(helloworld.java:9)
Ecco il mio codice
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class helloworld {
public static void main(String[] args) throws IOException {
Scanner KB = new Scanner(new File("file.txt"));
while (KB.hasNext()) {
String line = KB.nextLine();
System.out.println(line);
}
}
}
File.txt
ho creato file.txt nella stessa cartella nel mio progetto.
Il file si trova direttamente nella cartella del progetto? –
è sotto SCR, ho messo uno sotto il cestino, perché scr non ha funzionato. – Mowgli
Prova a stampare 'new File (" file.txt "). Exists()' Sta producendo 'true'? in caso contrario, prova a stampare 'new File (" file.txt "). getAbsoluteFile()' È quello che ti aspettavi? – amit