我想像这样重定向stdin
java foo < test.txt并在函数中逐字节读取test.txt。我只想这么做:
FileInputStream f = new FileInputStream(System.in)这应该非常简单,但我一直在绞尽脑汁,因为我想不出一种不使用argsx的方法来抓取test.txt。
编辑:问题是我这样做:
FileInputStream readByte = new FileInputStream(file);
char c = (char)readByte.read();它不会给出与
char c = System.in.read(); 发布于 2017-06-30 03:14:20
不确定这是否是你想要的,但看看这个问题:
Reading in from System.in - Java
他们使用以下方法:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Printing the file passed in:");
while(sc.hasNextLine()) System.out.println(sc.nextLine());
}https://stackoverflow.com/questions/44833167
复制相似问题