java how to read command line arguments code example

Example 1: java command line arguments

class CommandLineExample{  
public static void main(String args[]){  
System.out.println("Your first argument is: "+args[0]);  
}  
}

//Now follow these steps
compile by > javac CommandLineExample.java  
run by > java CommandLineExample sonoo

Example 2: java read file from command line argument

import java.util.Scanner;
import java.io.File;
Scanner input = new Scanner(new File(args[0])); //Where args[0] is the cmd argument, the file name