Salve a tutti , ho un problema con la lettura di un file da Java . Il nome del file è "a.txt" e contiene delle stringhe. Il codice è il seguente
Nella compilazione non mi da errori, ma quando vado ad eseguire mi da il seguente errorecodice:import java.io.*; public class Esempiofile { public static void main (String args []) throws FileNotFoundException, IOException { FileReader fr = new FileReader("C:\\Users\\Carme\\OneDrive\\Desktop\\a.txt"); BufferedReader br = new BufferedReader(fr); String line = br.readLine(); while(line != null) { System.out.println(line); line = br.readLine(); } } }
Potete dirmi dove sta il problema,graziecodice:Exception in thread "main" java.io.FileNotFoundException: C:\Users\Carme\OneDrive\Desktop\a.txt (Impossibile trovare il file specificato) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:213) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:155) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:110) at java.base/java.io.FileReader.<init>(FileReader.java:60) at esempiofile.Esempiofile.main(Esempiofile.java:16) C:\Users\Carme\AppData\Local\NetBeans\Cache\11.3\executor-snippets\run.xml:111: The following error occurred while executing this line: C:\Users\Carme\AppData\Local\NetBeans\Cache\11.3\executor-snippets\run.xml:68: Java returned: 1

Rispondi quotando

