提供标准输入以通过文件进行编程,并将标准输出带入文件 [英] Give standard input to program through files and take standard output to a file
问题描述
如何通过文件向Java程序提供标准输入并将标准输出获取到文件?
How to give standard input to java program through files and take standard output to a file?
我不想让程序使用文件输入法.程序应从BufferedReader之类的标准输入中获取输入,但是在运行时,输入应从文本文件中获取,而不是通过键盘输入.同样,程序生成的输出应重定向到文本文件.我认为有一些与javac/java命令相关的选项.但是我不完全知道.有人可以指导我该怎么做吗?我正在Windows 7、32位系统上使用jdk1.7
i don't want to make the program to make use of file input methods. program should take input from standard input like BufferedReader, but at runtime input should be taken from a text file and not through keyboard. Similiarly, the output generated by the program should be redirected to a text file. I think there is some option associated with the javac/java command. But i don't exactly know. Can someone guide me how to do this? I am using jdk1.7 for windows 7, 32 bit system
推荐答案
您可以使用操作系统重定向运算符
You can use OS redirection operators
java Test < inputFile > outputFile
然后这个
public class Test {
public static void main(String[] args) throws IOException {
for(int i; (i = System.in.read()) != -1;) {
System.out.write((byte)i);
}
}
}
将从输入文件复制到输出文件
will copy from inputFile to outputFile
这篇关于提供标准输入以通过文件进行编程,并将标准输出带入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!