Last active
December 12, 2016 23:53
-
-
Save jjlumagbas/82d7c32de0d3dc983853e1243f9f3d0c to your computer and use it in GitHub Desktop.
How to read command line arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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