Skip to content

Instantly share code, notes, and snippets.

@Hoolean
Created March 29, 2014 23:58
Show Gist options
  • Save Hoolean/9865035 to your computer and use it in GitHub Desktop.
Save Hoolean/9865035 to your computer and use it in GitHub Desktop.
Command Line File in Java
// this should be in your main class - more on that later
public static void main(String[] args)
{
System.out.println(args);
/*
If user ran:
java -jar FuelChecker.jar check diesal
Output: (or similar)
{"check", "diesal"}
*/
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("check"))
{
// check fuel and stuff
}
else
{
System.out.println("Invalid command! Run the JAR with no arguments to see help.");
}
}
else
{
System.out.println("Usage: java -jar FuelChecker.jar check <fuel type>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment