Forums Register Login

Reading from a File, Need help

+Pie Number of slices to send: Send
When i am executing the code below by the command
javac ShowFile.java
java ShowFile

the output is Usage ShowFile File

java ShowFile TEST.TXT

output : FileNotFound

i don't understand the logic of this program, shall i create a file before executing a program or what ??
if yes then where shall i place the file, in the bin folder where jdk is installed ??
please help ??

+Pie Number of slices to send: Send
As indicated the program should be run like java ShowFile C:/MyFolder/test.txt
If you look at the code there are two Exceptions handled - one is to check whether you give the file name as a command line argument and the other to check if the given file exists. So please create the file before giving it as an argument.
+Pie Number of slices to send: Send
 

shivang sarawagi wrote:if yes then where shall i place the file, in the bin folder where jdk is installed ??


NEVER place anything in the jdk bin folder. it's just a bad idea.

That folder is for JDK stuff. would you put files in the windows bin directory?

The whole reason for having a file structure is to keep stuff separated. you don't want to start jumbling unrelated things together.

Your question has probably already been answered, but let me make an additional comment. If your path contains space, you will have to enclose it in quotes:

java ShowFile "c:/My Document/fred/test.txt"

using the full path will always work. I believe that if the file is in the directory where you are calling from, you can just give it the name.
+Pie Number of slices to send: Send
i thank you both John & Fred for your prompt replies !!
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1428 times.
Similar Threads
FileInputStream Initialization...
Query in code of displaying a text file
meaning of return; only
Error occure
Explanation
More...

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