File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Query in code of displaying a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query in code of displaying a text file" Watch "Query in code of displaying a text file" New topic
Author

Query in code of displaying a text file

shivang sarawagi
Ranch Hand

Joined: Jun 19, 2008
Posts: 148


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
John Jai
Bartender

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

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

Joined: Oct 13, 2005
Posts: 39793
    
  28
Does that example really use try-catch to test whether you have no arguments?
shivang sarawagi
Ranch Hand

Joined: Jun 19, 2008
Posts: 148
thats what !! i am confused about this line


can anyone help ??
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39793
    
  28
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

Joined: Jun 19, 2008
Posts: 148
yes i had doubt in args[0], well thanks a lot Ritchie, the link is informative.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39793
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query in code of displaying a text file