Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get name of input file (at commandline )

 
D. Nguyen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
D. Nguyen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, I think the only way is to access the parameter list in main().
Sorry!
Darrin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic