?
Solved

Arguement From Command Line

Posted on 2003-03-08
3
Medium Priority
?
200 Views
Last Modified: 2010-03-31
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
Comment
Question by:wazdaka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 8094030
public static void main (String args[]) {
  String xyz = args[0];
 }
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8094035
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
 

Author Comment

by:wazdaka
ID: 8094063
Thanks CEHJ, as ever, fast and useable answer.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question