Command Line Pipe Input in Java

前端 未结 4 689
忘掉有多难
忘掉有多难 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:04

    Is there a way by which I can make the Standard In(Command Line) active after the file being fed into the code is done?

    Sorry to bump an old question, but none of the answers so far points out that there is a (shell-only) way to pass back to console input after piping in a file.

    If you run the command

    { cat input.txt & cat; } | java Read
    

    then the text from input.txt will be passed to java Read and you will then be dropped back to console input.

    Note that if you then press Ctrl+D, you will get the infinite loop of nulls, unless you modify your program to end the loop when it receives null.

提交回复
热议问题