aspose file tools*
The moose likes Beginning Java and the fly likes Reading from a File, Need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading from a File, Need help " Watch "Reading from a File, Need help " New topic
Author

Reading from a File, Need help

shivang sarawagi
Ranch Hand

Joined: Jun 19, 2008
Posts: 148
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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Oct 02, 2003
Posts: 11420
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
shivang sarawagi
Ranch Hand

Joined: Jun 19, 2008
Posts: 148
i thank you both John & Fred for your prompt replies !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading from a File, Need help