我有一个关于 Java 中 String[] args 使用的问题:
......
public static void main(String[] args) throws Exception {
new EMR().start(args);
}
public void start(String[] args) throws Exception {
File recordFile = new File(args[0]);
File instructionFile = new File(args[1]);
File outputFile = new File(args[2]);
.......
这只是文件读取的一个示例,所以如果我想运行代码并将实际文件名/路径放入 main() 方法,我该如何实现它,例如,我可以这样写:
new EMR().start(1.txt,2.txt.3.txt)
最佳答案
像这样在命令行上传递参数
C:\myfolder> java HelloWorld hi java world
其中 HelloWorld 是 java 类名,hi java world 是参数,例如: hi = args[0] 、 java = args[1] 、 hello = args[ 2]
关于java - args[] 用于文件读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19345862/