Click here to Skip to main content
16,016,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am very new to java please help me

how to pass arguments as text file and integer number in java.

e.g java routing.java inputfile 2
Posted

1 solution

More or less as you have shown above, except that you do not try to run the .java file. You first need to compile your Java source with the javac command, and then run the class file thus:
javac routing.java
java routing inputfile 2

The input parameters are then accessed from the args argument of the main() method. The following code demonstrates the basic functionality:
Java
public static void main(String[] args) {
    if (args.length > 0) {
        System.out.println("Application arguments:");
        for (String argName : args) {
            System.out.format("\t%s%n", argName);
        }
        System.out.println("");
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900