I am trying to use the class Scanner
but, although I have tried several changes, it continues throwing FileNotFoundException
, please if someone had an idea.
Here I put the code
package youtube;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class scaner {
public static void main(String[] args) throws FileNotFoundException {
String fileName = "C:\Users\0d sat\Desktop\example.txt";
File textFile = new File(fileName);
Scanner in = new Scanner(textFile);
int value = in.nextInt();
System.out.println("Read value: " + value);
in.nextLine();
int count = 2;
while(in.hasNextLine()) {
String line = in.nextLine();
System.out.println(count + ": " + line);
count++;
}
in.close();
}
}
throws:
Exception in thread "main" java.io.FileNotFoundException: C:\Userspackage youtube;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class scaner {
public static void main(String[] args) throws FileNotFoundException {
String fileName = "C:\Users\0d sat\Desktop\example.txt";
File textFile = new File(fileName);
Scanner in = new Scanner(textFile);
int value = in.nextInt();
System.out.println("Read value: " + value);
in.nextLine();
int count = 2;
while(in.hasNextLine()) {
String line = in.nextLine();
System.out.println(count + ": " + line);
count++;
}
in.close();
}
}
d sat\Desktop\example.txt (El sistema no puede encontrar el archivo especificado)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.util.Scanner.<init>(Scanner.java:611)
at youtube.scaner.main(scaner.java:15)