Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Arguement From Command Line

Hi all

A quick (hopefully!) question. How would I grab an arguement from the command line when running a java program. Eg,

public class Myparse {

  public static void main (String args[]) {
  }
}

is the bones, how would I grab the first arguement from the command line, as a string. eg

$ java Myparse "xyz"

where "xyz" is what I want to grab.

Thanks

0
wazdaka
Asked:
wazdaka
  • 2
1 Solution
 
CEHJCommented:
public static void main (String args[]) {
  String xyz = args[0];
 }
0
 
CEHJCommented:
This constuction is useful when you have command line arguments. Question marks should be replaced by the number of arguments you want to check for. 'Usage' should be followed by the name of the application and the arguments that it expects:

if(args.length < ?????????){
 System.out.println("Usage: java ????");
 // Exit if args wrong
 System.exit(-1);
}
0
 
wazdakaAuthor Commented:
Thanks CEHJ, as ever, fast and useable answer.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now