• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading from a File, Need help

 
shivang sarawagi
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??

 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shivang sarawagi
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thank you both John & Fred for your prompt replies !!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic