Skip to content

Instantly share code, notes, and snippets.

@jjlumagbas
Last active December 12, 2016 23:53
Show Gist options
  • Save jjlumagbas/82d7c32de0d3dc983853e1243f9f3d0c to your computer and use it in GitHub Desktop.
Save jjlumagbas/82d7c32de0d3dc983853e1243f9f3d0c to your computer and use it in GitHub Desktop.
How to read command line arguments
class ReadArgs {
public static void main(String[] args) {
System.out.println(args.length);
if (args.length >= 1) {
System.out.println("Running commands in file: " + args[0]);
} else {
System.out.println("No args provided. Running in interactive mode");
}
}
}
/*
~/scratch
▶ javac ReadArgs.java
~/scratch
▶ java ReadArgs hello
1
Running commands in file: hello
~/scratch
▶ java ReadArgs mp4.in
1
Running commands in file: mp4.in
~/scratch
▶ java ReadArgs
0
No args provided. Running in interactive mode
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment