[英]How can I read the arguments from a text file while running java
I have the below code 我有以下代码
public class prob01 {
public static void main (String arg[]) {
System.out.println(arg[0]);
}
}
I have a text file prob01.txt in the same directory which contains: 我在同一目录中有一个文本文件prob01.txt ,其中包含:
StackOverflow StackExchange StackOverflow StackExchange
How can I get the output as StackOverflow from the above code when I give the arguments as prob01.txt like below: (I dont want to modify the java code, the dos has to take care of parsing the file and sending the contents as arguments) 当我像下面这样给prob01.txt提供参数时,如何从上面的代码中获得StackOverflow的输出:(我不想修改Java代码,Dos必须照顾好文件的解析并将内容作为参数发送)
C:\> javac prob01.java
C:\> java -cp . prob01 < prob01.txt
您需要在Java代码中使用Reader来读取文件的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.