Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Reading from a File, Need help

 
Ranch Hand
Posts: 159
  • 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 ??

 
Rancher
Posts: 1776
  • 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.
 
lowercase baba
Posts: 12839
52
Chrome Java Linux
  • 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: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thank you both John & Fred for your prompt replies !!
 
The only cure for that is hours of television radiation. And this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic