Is there a way to redirect input from file to stdin in Netbeans?

后端 未结 5 1381
忘了有多久
忘了有多久 2020-12-31 09:11

I\'m developing application with Netbeans and Maven. My application should obtain data from stdin. But I could not understand how to test it. Putting < data.txt

5条回答
  •  梦谈多话
    2020-12-31 09:37

    I assume you have a thing like:

    public static void main(String[] args) {
    ...
    }
    

    This can used as an entry point to your application and before that you change the input channel via:

    FileInputStream is = new FileInputStream(new File("test.data"));
    System.setIn(is);
    

    The above can be used within a unit/integration test.

提交回复
热议问题