What is current directory? Try printing new File ". Print the path of new File "scores. Steinar it is searching in the correct directory, and it is giving the correct absolute path, however, the file is still not found — scrblnrd3.
What is the text of the exception? It's almost certain that you're in the wrong directory. Print new File "scores. Show 3 more comments. Active Oldest Votes. The named file does not exist. This could be for a number of reasons including: The pathname is simply wrong The pathname looks correct but is actually wrong because it contains non-printing characters or homoglyphs that you did not notice The pathname is relative, and it doesn't resolve correctly relative to the actual current directory of the running application.
This typically happens because the application's current directory is not what you are expecting or assuming. The path to the file is is broken; e. The named file is actually a directory.
The named file cannot be opened for reading for some reason. Here are some things that you can try: Calling file. This line will tell you what the current directory is: System. It turns out that your example code has a compilation error. I ran your code without taking care of the complaint from Netbeans, only to get the following exception message: Exception in thread "main" java. FileNotFoundException; must be caught or declared to be thrown If you change your code to the following, it will fix that problem.
Vili 1, 14 14 silver badges 38 38 bronze badges. Terry Li Terry Li Your third case includes the other two, and also includes a number of other easily separable cases such as permission problems, network failures, etc.
Testing File. Add a comment. Use this line and see where the path is: System. Obviously there are a number of possible causes and the previous answers document them well, but here's how I solved this for in one particular case: A student of mine had this problem and I nearly tore my hair out trying to figure it out.
Hope this helps others save themselves some hair. There are a couple of things that you can help to spot this kind of problem: Output the pathname with quote characters around it; e. Irina Larisa Irina Larisa 51 1 1 silver badge 3 3 bronze badges. Solumyr Solumyr 3 3 bronze badges. Apart from all the other answers mentioned here, you can do one thing which worked for me.
It worked for me, hope it helps someone :. Alok Alok 58 1 1 silver badge 6 6 bronze badges. While this worked for you, there are problems with this approach. That won't work when you ship the code to someone else. If the file you are trying to read is part of your source code base, a better idea is to copy it into your JAR file or the file tree containing your compiled classes and use getResourceAsStream to find it via the runtime classpath. Aditya Vikas Devarapalli Aditya Vikas Devarapalli 2, 2 2 gold badges 30 30 silver badges 47 47 bronze badges.
Use single forward slash and always type the path manually. Read ;. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related 1. Hot Network Questions. By signing up, you agree to our Terms of Use and Privacy Policy. Forgot Password? This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy.
By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy.
Popular Course in this category. Course Price View Course. Free Software Development Course. Login details for this Free course will be emailed to you. Email ID. Contact No.
0コメント