import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @Command(name = "mytool", mixinStandardHelpOptions = true, version = "1.0", description = "A CLI tool for demonstration") public class MyTool implements Runnable { @Option(names = {"-v", "--verbose"}, description = "Verbose mode") private boolean verbose; @Parameters(index = "0", description = "Input file") private String inputFile; public void run() { } public static void main(String... args) { CommandLine.run(new MyTool(), args); } } @Command(name = "mytool", mixinStandardHelpOptions = true, version = "1.0", description = "A CLI tool for demonstration") public class MyTool implements Runnable { @Option(names = {"-a", "--optionA"}, description = "Option A") private boolean optionA; @Option(names = {"-b", "--optionB"}, description = "Option B") private int optionB; @Parameters(index = "0", description = "Input file") private String inputFile; public void run() { } // ... } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class InteractiveTool { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Welcome to Interactive Tool!"); System.out.print("Please enter your name: "); String name = reader.readLine(); System.out.println("Hello, " + name + "!"); } } import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class ConfigTool { public static void main(String[] args) throws IOException { Properties properties = new Properties(); FileInputStream fis = new FileInputStream("config.properties"); properties.load(fis); fis.close(); String username = properties.getProperty("username"); String password = properties.getProperty("password"); System.out.println("Retrieved username: " + username); System.out.println("Retrieved password: " + password); properties.setProperty("password", "newpassword"); FileOutputStream fos = new FileOutputStream("config.properties"); properties.store(fos, "Updated configuration"); fos.close(); } }


上一篇:
下一篇:
切换中文