java - 如何使用 IntelliJ 运行参数带 重定向符号 的程序?
PHPz
PHPz 2017-04-18 09:57:25
0
1
1221

这个问题的核心是 重定向符号

<

在命令行中,我可以这样执行程序:

java -cp /classpath MyClass < data.txt

即编译 MyClass.class 字节码文件成二进制码并运行,然后重定向 data.txt 到这个程序。
程序可以正常运行。

但是当我使用 Intellij 的时候问题就来了,
根据 官方帮助文档 我在 Program Argument 中只能输入参数名,如果输入了重定向符号,就会导致抛出异常

Exception in thread "main" java.lang.IllegalArgumentException.

有没有什么方法能在 IntelliJ 中给程序添加重定向?拜托了!!!

========= 关于“那你为什么不直接用命令行运行?贱人就是矫情!” ============
因为我要调试程序。

======= 关于“那你为什么不直接在命令行用jdb调试?贱人就是矫情!” =========
jdb这种东西 Oracle 官方都懒得推广,求放过。

PHPz
PHPz

学习是最好的投资!

reply all(1)
Ty80

Remembering that the question is about debugging the program, there is another way:
Run it on the command line and add the parameters
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4004
(the middle few I don’t know whether the parameters are necessary, but they are copied and pasted. Anyway, it is to enable debugging and open port 4004)
Then there is a remote method when running IDEA, which is equipped with a port.
Run from the command line, the program will stop and wait for the connection. You can connect to it for debugging by running remote debugging in IDEA.
(PS: I don’t know what will happen if the codes on both sides are different)

I can only think of one way to save the country:
If the questioner uses Scanner to read the command line,
Just new Sacnner(new File("...")) will do

By the way, IDEA is originally about setting parameters. Redirecting files is no longer a parameter. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!