|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Java Commandline Help
Hello, this is a problem which no one can seem to help me on in anyforums. I've seen this done in C,C++ and Java so these are very general questions:
let's say someone types this: Prompt> JavaProgram.jar -h -otherthing Wtf are those options? And how can I use those options in a java program? I mean, do they set variables for default inside the program? Do they set environment variables? If so, how do i code my application to receive options from commandline during execution/before/whenever? Because in alot of commandline progs -h designates help output, how do i code my program to act based on flag inputs during the execution of the program? I'm really confused so if someone could give me a general answer for a general bunch of questions... that'd be very cool. |
|
#2
|
||||
|
||||
|
Arguments passed to your program can be found within the string array that's passed to the main method.
|
|
#3
|
|||
|
|||
|
ahh, ic, so if I check the array for the tags I can use those options?
would I use the Object[] type? Could you give me an example of retrieving a flag from the array in the main method? |
|
#4
|
||||
|
||||
|
Off the top of my head and untested:
Code:
public static void main(String[] args) {
for(int i=0;i<args.size();i++) {
System.out.println("Argument "+i+": "+args[i]);
}
}
|
|
#5
|
|||
|
|||
|
cool man thanks alot
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Java Commandline Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|