Forums Register Login

try catch cannot read file

+Pie Number of slices to send: Send
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.

1
+Pie Number of slices to send: Send
solved the problem by placing the full path of the file
+Pie Number of slices to send: Send
Well done

Try a JFileChooser to find the files. You may have to pass null for the component for the dialogue to appear over.
+Pie Number of slices to send: Send
Hi ,Irving Luna.

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
+Pie Number of slices to send: Send
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.

Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 437 times.
Similar Threads
Writing a class file to read text file.
I/O problem
array question?
Parsing a text file to an arraylist
How to make Stem and plot in java ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:01:02.