This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Read the name of the input file from cl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read the name of the input file from cl" Watch "Read the name of the input file from cl" New topic
Author

Read the name of the input file from cl

David McHugh
Greenhorn

Joined: Oct 01, 2008
Posts: 23
hi,

i have to input a simple text file called text1.txt into my program called Input1.java, but i cannot code the filename into program e.g.

FileInputStream f;
try {
f = new FileInputStream("text1.txt");

i have to take it from the cl, e.g. when running the program type java Input1 text1.txt

any ideas?
Satish Chilukuri
Ranch Hand

Joined: Jun 23, 2005
Posts: 266
Command line args
David McHugh
Greenhorn

Joined: Oct 01, 2008
Posts: 23
cheers satish
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Just to make you aware. For any medium scale application, handling command line arguments become a bit troublesome specially when it comes to maintenance.

Libraries like Apache Commons CLI makes your life easy.
Needless to say, this is *only* required if you have (or expect to have) extensive command line options and will be an overkill for less command line options.
[ November 12, 2008: Message edited by: Nitesh Kant ]

apigee, a better way to API!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read the name of the input file from cl