Java命令行參數處理 CLOPS
CLOPS 是一個用來處理 Java 程序中的命令行參數的類庫。
示例代碼:
import java.io.File;
import generated.WcParser;
import generated.WcOptionsInterface;
public class Main {
public static void main(String[] args) throws Exception {
WcParser parser = new WcParser();
if (!parser.parse(args)) {
System.out.println("Usage: java Main [OPTIONS] file...");
System.exit(1);
}
WcOptionsInterface opt = parser.getOptionStore();
if (opt.isWordsSet())
System.out.println("I should print a word count.");
if (opt.isBytesSet())
System.out.println("I should print a byte count.");
for (File f : opt.getFiles()) checkFile(f);
}
public static void checkFile(File f) {
System.out.print("The file " + f.getPath());
if (f.exists())
System.out.println(" exists.");
else
System.out.println(" does not exist.");
}
}
本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!