[英]how to pass string arguments in java as argument at runtime
I am new to Java I need help with as how can I take values at runtime when a Java file is executed. 我是Java的新手,我需要帮助,因为执行Java文件时如何在运行时获取值。 I have Java program where the values of host,user, password and command is hardcoded, how can I parmeterize it. 我有一个Java程序,其中host,user,password和command的值是硬编码的,如何对其进行参数化。 eg, 例如,
public static void main(String[] args) {
String host="ssh.journaldev.com";
String user="sshuser";
String password="sshpwd";
String command1="ls -ltr";
try{....
Can we make any changes such that at runtime on cmdline i can pass all values. 我们可以进行任何更改,以便在cmdline上运行时我可以传递所有值。 eg. 例如。
java -jar testjava ssh.journaldev.com sshuser sshpwd "ls -ltr"
this should be executed. java -jar testjava ssh.journaldev.com sshuser sshpwd "ls -ltr"
应该执行。
Yes this is done like the following: 是的,这是通过以下方式完成的:
String name = args[0];
String user = args[1];
String password=args[2];
String command1=args[3];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.