Simple Basic Java Software – analysing arguments from command line

Problem

You want a simple bit of java code that takes arguments from the command line and displays them.



Solution

Good demo on how to obtain and handle java arguments.

public class Arguments {  public static void main(String argv[]) {    if(argv.length > 0) {      System.out.println("args exec w " + argv.length + " args");        for(int i=0;i...


Example


Here is a demo:

# java Arguments -a -x -yargs exec w 3 argsargv[0] = -aargv[1] = -xargv[2] = -y


Reference



Leave a Reply

Your email address will not be published. Required fields are marked *