Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing in a file from the command line

 
April Benzine
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to pass in a text file from the command line to a class that reads it in, processes and counts its tokens then prints it out to a .dat file in my output directory. how do I connect what is entered in on the command line with the variable I have created in my class (it cannot be hard coded in my class)?

Here's my code:



[Edited to add UBB Code tags to make code reading easier - GB]

Please help
[ September 29, 2004: Message edited by: Gregg Bolinger ]
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, April -

My first question would have to be, where is your main method? The command-line arguments come into the program via main. Do you have another, driver program that invokes this class and its methods? Also, what error are you seeing? Compile-time, run-time, logical?

With more info, maybe I (or another visitor) can help.

Thanks,

Jeff
[ September 29, 2004: Message edited by: Jeff Bosch ]
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Just out of curiosity, why are these variables public instead of private, like the other variables? This would expose your variables to outside modification.
 
April Benzine
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those were just the specs of the project's class diagram
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I ask what this project is for?
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldn't get either file to compile as is. I had 15 compiler errors with the AnalyzeFile and 21 with the driver program.

Is some code missing? Perhaps your import statements? Custom packages or classes? (The classes TokenCount and PropertiesManager aren't part of the standard API's that I can see.)
[ September 29, 2004: Message edited by: Jeff Bosch ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In your other post you write:

But why == 2 ?
Coming from c/c++?
args[0] is the first parameter in java, not the program-name.
One file argument leads to (args.length == 1).
[ September 29, 2004: Message edited by: Stefan Wagner ]
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
get data from command.

Run java program
java Test

Output
nothing

Run java program
java Test test1 test2 test3

Output
test1
test2
test3

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, you should use Property file , it more flexible than current solution.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so.
A parameter is immediately typed at the commandline, and if you prefer mice, you may move a file from the explorer to your well-defined jar, if you want your program to process that filename in some way (open the file, for example).
A properties-file needs to be found, edited, saved ..., you need backups to process older commands, while the commandline can have a history of thousends of calls...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic