有没有办法在Netbeans中将输入从文件重定向到stdin?

有没有办法在Netbeans中将输入从文件重定向到stdin?

问题描述:

我正在使用Netbeans和Maven开发应用程序。我的应用程序应该从stdin获取数据。但我无法理解如何测试它。放< data.txt 进入args列表不起作用。

I'm developing application with Netbeans and Maven. My application should obtain data from stdin. But I could not understand how to test it. Putting < data.txt into args list does not work.

我需要相同的:

$ java MyProgram < data.txt 


这可以通过添加自己的将target运行到项目的build.xml文件中。例如:

This can be done by adding your own run target to your project's build.xml file. For example:

<target name="run" depends="jar">
  <exec dir="${work.dir}" executable="java" input="${work.dir}/inputfile.txt">
    <arg value="-jar"/>
    <arg file="${dist.jar}"/>
  </exec>
</target>

请注意,如果编译,Run,Debug和Test等命令仅使用自定义build.xml关闭项目的保存功能。因此,您需要确保在项目的属性中关闭保存时编译。

Note that commands such as Run, Debug, and Test only use your custom build.xml if the Compile on Save feature is turned off for the project. So you will need to ensure that Compile on Save is turned off in your project's properties.