Java read file by command line, <(less than) symbol

前端 未结 4 609
谎友^
谎友^ 2021-01-15 21:24

I am trying to read the filename by the command line,

This is command that our professor wants us to type:

java MultiBinaryClient xxxxxx.edu 6001 <         


        
相关标签:
4条回答
  • 2021-01-15 21:42

    Let's see what each fragment means. This is how we execute a Java class containing a main method:

    java MultiBinaryClient
    

    The only command-line arguments that are being passed to your program are these ones:

    xxxxxx.edu 6001
    

    And this snippet is not part of the expected arguments to the Java program:

    < files.txt
    

    It's just Unix shell syntax to specify that the contents of files.txt must be read into your program via the standard input.

    0 讨论(0)
  • 2021-01-15 21:52

    You should escape the '<'

    java MultiBinaryClient xxxxxx.edu 6001 \< files.txt
    
    0 讨论(0)
  • 2021-01-15 21:54

    < is a redirection. The file will be streaming over stdin.

    0 讨论(0)
  • 2021-01-15 22:04

    I know it's an old question, but I've had this problem recently. Here's what I've done to handle it:

    Well, as the others said, the "<" redirects the file contents to stdin. If you want to use the file contents as program arguments, you can use xargs:

    xargs -a FILE java JAVA_ARGS
    

    or, more specifically:

    xargs -a FILE java -cp CLASSPATH CLASS_WITH_MAIN_METHOD
    
    0 讨论(0)
提交回复
热议问题