FileNotFoundException (The system cannot find the file specified) error.

已回答

As the title says. I keep getting this error.

package test01;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class dfgdf {
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Hello World!");
Scanner input = new Scanner(new File ("/src/file/bruh.txt"));
String answer = input.nextLine();
System.out.println(answer);
}
}

I was just trying to test to see if this error was only on my laptop but as it turns out, its also an error on my desktop so maybe im doing something wrong

0

See if it helps to remove the leading "/" character from the file path:

Scanner input = new Scanner(new File("src/files/bruh.txt"));
1

请先登录再写评论。