Command Line Pipe Input in Java

前端 未结 4 724
忘掉有多难
忘掉有多难 2020-12-05 08:24

Here is a simple piece of code:

import java.io.*;
public class Read {
 public static void main(String[] args) {
     BufferedReader f = new BufferedReader(ne         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 09:11

    By executing "java Read < input.txt" you've told the operating system that for this process, the piped file is standard in. You can't then switch back to the command line from inside the application.

    If you want to do that, then pass input.txt as a file name parameter to the application, open/read/close the file yourself from inside the application, then read from standard input to get stuff from the command line.

提交回复
热议问题