Im running this method but for some reason I am not able to find the data record, it keeps going to the catch. Can somebody let me know where I am messing up please. I have the data.txt file in the same directory as the java file.
There is no need to give the complete path , instead you can provide the relative path.
Means, suppose your java class and data.txt file are inside the com.company.project.module.games package under src folder then
you can declare the Scanner class as follows
To get started, using the full path to the file is a reasonable thing to do. Providing the relative path is also reasonable, but then you have to know what the current working directory is. (My impression is that a lot of beginners haven't even heard of the "current working directory" concept, which is unfortunate.)
However I don't think that assuming the code is going to be run from an IDE, as Dileep just did, is the right thing to do. Because as soon as you try to run the application outside the IDE, your CWD (current working directory...) is different and your application stops working.
Post by:autobot
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards