有没有办法将输入从文件重定向到 Netbeans 中的标准输入? [英] Is there a way to redirect input from file to stdin in Netbeans?

查看:24
本文介绍了有没有办法将输入从文件重定向到 Netbeans 中的标准输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Netbeans 和 Maven 开发应用程序.我的应用程序应该从标准输入获取数据.但我无法理解如何测试它.把 到 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 

推荐答案

这可以通过将您自己的运行目标添加到项目的 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>

请注意,如果项目的保存时编译"功能已关闭,则运行、调试和测试等命令仅使用您的自定义 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.

这篇关于有没有办法将输入从文件重定向到 Netbeans 中的标准输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆