Home Java Java-get-example Java program to get the Command Line Arguments

Related Tutorials


 
 

Share on Google+Share on Google+

Java program to get the Command Line Arguments

Advertisement
In java we can get the command line arguments as they are provided on the console. In this example program our program takes arguments from the console and print it on the console.

Java program to get the Command Line Arguments

     

In java we can get the command  line arguments as they are provided on the console. In this example program our program takes arguments from the console and print it on the console.

In our example program we can use the string array variable args for holding command line arguments. Here is the full example code of GetCommandLine.java as follows:

 

 

GetCommandLine.java

public class GetCommandLine
{
  public static void main(String args[]) {
  System.out.println("----->>Getting command line arguments --");
  for(int i=0;i<args.length;i++)
  {
  System.out.println("Argument ["+(i+1)+"] is = "+args[i]);
  }
  }
}

 

Output:

C:\javaexamples>javac GetCommandLine.java

C:\javaexamples>java GetCommandLine Amit Kumar
---------->> Getting command line arguments --
Argument [1] is = Amit
Argument [2] is = Kumar

 

Download Source Code

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2008

Related Tutorials

Discuss: Java program to get the Command Line Arguments   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
sravani
April 16, 2011
java

write a java program to accept a file name as command line argument.Append the string "File modified by program" to the end of the same file and print the contents of the modified file?
suraj jaiwal
August 30, 2012
java programming

like
DMCA.com