我不是100%肯定态度,但我看了看蚂蚁的源代码,它只是做了的readLine():
从/组织/阿帕奇/工具/ ANT /输入/ DefaultInputHandler.java:
/**
* Prompts and requests input. May loop until a valid input has
* been entered.
* @param request the request to handle
* @throws BuildException if not possible to read from console
*/
public void handleInput(InputRequest request) throws BuildException {
String prompt = getPrompt(request);
BufferedReader r = null;
try {
r = new BufferedReader(new InputStreamReader(getInputStream()));
do {
System.err.println(prompt);
System.err.flush();
try {
String input = r.readLine();
request.setInput(input);
} catch (IOException e) {
throw new BuildException("Failed to read input from"
+ " Console.", e);
}
} while (!request.isInputValid());
} finally {
if (r != null) {
try {
r.close();
} catch (IOException e) {
throw new BuildException("Failed to close input.", e);
}
}
}
}
这里是如果我是你,我会做什么:
- 如果您使用Ant 1.7,然后尝试实现自己的InputHandler,如documentation描述。 Apache许可证允许您基本上复制并粘贴上述代码作为起点。
- 如果您使用的是Ant 1.6或更早版本,那么只需创建您自己的MultiLineInput任务。您可以扩展现有的Input类并只读多行。
无论哪种情况,您都需要决定用户如何表示“我完成了”。您可以使用空白行或句点或其他内容。
祝你好运!
P.S.当我做了一个“蚂蚁多行输入”的谷歌搜索,这个页面是第一次击中:-)。对于不到一个小时前问过的问题来说,这是相当不错的。
感谢您的源代码。 – 2009-04-09 21:01:34