This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Get name of input file (at commandline ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Get name of input file (at commandline )" Watch "Get name of input file (at commandline )" New topic
Author

Get name of input file (at commandline )

D. Nguyen
Greenhorn

Joined: Jun 09, 2006
Posts: 5
Hi,

When i'm calling a program, for example java Test <input.txt
i'd like to get the name of the file, in this example input.txt
How should i do this? I'm making a new DataInputStream(System.in), but I have no idea how I can get the name of the inputfile (because you also can't acces it in the args array of the mainmethod).
Thanks in advance.
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
Hello,

Why can't you access the filename as a parameter to main()?

Anyway, you could always pass in the name of the file as a "System Property" on the command line. Something like:


Good luck!


Life is good on the Ponderosa,<br />but mind where you step.
D. Nguyen
Greenhorn

Joined: Jun 09, 2006
Posts: 5
Thanks, but i'm looking for a way to do this without extra typing at the command line
so just when i type java Test <input.txt
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
In that case, I think the only way is to access the parameter list in main().
Sorry!
Darrin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get name of input file (at commandline )