【发布时间】:2014-01-15 22:00:16
【问题描述】:
我的代码中有一个我正在阅读的文本文件的硬编码名称。
String fileName = "test.txt";
但是我现在必须像这样使用命令参数:
text.java arg1 arg2 arg3 (can be any amount) < test.txt
谁能帮帮我?
我得到参数没问题,只是不确定文件。谢谢
我试过了:
String x = null;
try {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
while( (x = f.readLine()) != null )
{
System.out.println(x);
}
}
catch (IOException e) {e.printStackTrace();}
System.out.println(x);
}
但是我的应用程序现在挂在 readLine 上,请问有什么想法可以尝试吗?
【问题讨论】:
-
向我们展示如何获取参数(代码)。
-
这样,您只将 test.txt 的内容传递给标准输入,而不是文件名。
-
@GaborBakos 啊,这更有意义,我编写了代码以根据名称阅读它。谢谢
-
@MariuszS 我用于 (int j = 0; j
标签: java