Redirect stdin from a file in eclipse with run configuration

后端 未结 3 1018
醉酒成梦
醉酒成梦 2020-12-19 03:31

There used to be a bug in eclipse that prevented a run configuration from redirecting a file to stdin but supposedly it\'s fixed. However, I can\'t find any documentation t

相关标签:
3条回答
  • 2020-12-19 03:50

    This is the announcement and description of the feature for Eclipse 4.5 (Mars): http://eclipse.org/mars/noteworthy/#_assigning_stdin_to_a_file

    Stdin can now be assigned to a file in the Common tab of launch configuration dialogs. enter image description here

    As expected, this is a new feature of the just released Eclipse 4.5 and will therefore not work in an older version.

    0 讨论(0)
  • 2020-12-19 04:10

    I hope I understand correctly.

    The file needs to have new line at the end.

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(scanner.next());
        }
    }
    

    File to contain a text (and ends with an new empty line, not only a text).

    Then Run Configuration | Common | Input File

    And the program will print the file content.

    Edit: Build id: 20150621-1200

    0 讨论(0)
  • 2020-12-19 04:12

    You will need Eclipse Mars for this, as the bugfix was not backported.

    Go into Run Configurations, open your Java Application. In the Common tab, there is a Standard Input and Output group, where you can define an input file.

    0 讨论(0)
提交回复
热议问题