开发者

File read not finding file

开发者 https://www.devze.com 2023-02-11 05:10 出处:网络
Scanner fileScanner = new Scanner(new File(\"C:/Users/User1/Documents/ServerSettings.dat\")); The code above cannot find the file specified. It definitely exis开发者_运维技巧ts at the location speci
Scanner fileScanner = new Scanner(new File("C:/Users/User1/Documents/ServerSettings.dat"));

The code above cannot find the file specified. It definitely exis开发者_运维技巧ts at the location specified.

The error given is:

java.io.FileNotFoundException: C:\Users\User1\Documents\ServerSettings.dat (The system cannot find the file specified)


Is it because you're trying to construct a new file instead of a new File? If so, that would likely result in a compile-time error unless you've got a custom class named file on your classpath.


If your code isn't compiling it's because you have file with a lowercase 'f' in new file part of the code. If this is right in your code and your problem is at runtime try

System.out.println( "exists? " + new File("C:/Users/User1/Documents/ServerSettings.dat").exists() );

to see if the file really does exist Or copy and paste the file path to windows explorer.

0

精彩评论

暂无评论...
验证码 换一张
取 消