简体   繁体   中英

Optional Parameters in MAIN() for JAVA

Is it possible to implement optional parameters for a Java program?

I tried searching this up, but all that came up was for overloading methods in Java, not specifically the main().

What I'm trying to do is run a Java program with an optional flag, ie:

~ java Program textfile.txt [optional flag]

where Program must run with a supplied text file, but not necessarily optional flag.

All arguments are in args parameter of main. You must implement the logic for processing it.

If you are feeling lazy and want to try some libraries, have look at Apache Commons CLI library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM