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

Query in code of displaying a text file

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


code cited from java complete reference

i have two questions
A. Where should the file "TEST.TXT" be kept ??
B. Why is args[0] given as an argument


Thanks
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can see the answer in the comments specified above the class.

/* Display a text file.
To use this program, specify the name
of the file that you want to see.
For example, to see a file called TEST.TXT,
use the following command line.
java ShowFile TEST.TXT
*/

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies i missed to answer (A) - you can have it any where and should send the correct path as the command line argument to the program...

say java ShowFile C:/MyFolder/TEST.TXT
 
Marshal
Posts: 69052
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that example really use try-catch to test whether you have no arguments?
 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats what !! i am confused about this line


can anyone help ??
 
Campbell Ritchie
Marshal
Posts: 69052
275
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which bit are you confused about? That is straighforward enough.
FileInputStream "the next variable will be of type FileIn...."
fin "I am going to call that variable fin."
= "take whatever is on the right of this operator and give that value to the name on the left"
new "an operator which tells the JVM there will be a new object"
FileInputStream(...) "the object will be of type FileIn... and the JVM is to call its constructor with the arguments in the ()"
new "same as before"
File(...) "the object will be of type File, and the JVM is to call its constructor with the arguments in the ()"
args[0] "the first word you wrote after the name of the class when you went to the command line."
; "End of this statement: go and look for the next statement."

If it is args[0] you were confused about, try here.
 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i had doubt in args[0], well thanks a lot Ritchie, the link is informative.
 
Campbell Ritchie
Marshal
Posts: 69052
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
    Bookmark Topic Watch Topic
  • New Topic