尽管我输入了正确的日期,但是如果我在其他地方输入内容,那将是一个错误。我想知道如何将多个输入写入命令提示符。例如,我将"05-13-2018"用作变量writer.write()。如果我也想在代码下面输入任何值,然后执行该代码,请问有什么办法。如果您不了解我要达到的目标,请给我发消息。再次感谢你的帮助
import java.io.*;
import java.util.ArrayList;
public class command{
public static void main(String[] args) {
String command="cmd /c date";
try {
Process process = Runtime.getRuntime().exec(command);
OutputStreamWriter outputt = new OutputStreamWriter(process.getOutputStream());
BufferedWriter writer = new BufferedWriter(outputt);
writer.write("05-13-2018");
writer.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
温温酱
相关分类