how to interrupt a scanner.nextline() call

前端 未结 4 428
忘了有多久
忘了有多久 2021-01-22 19:58

There are many threads on SO about interrupting reading the system.in but what I am looking for here is some kind of advice as to how to best code what I am trying to achieve.

4条回答
  •  鱼传尺愫
    2021-01-22 20:54

    Why not just poll with System.in.available() if there are bytes to read? It is non-blocking: one can do the call to Scanner.nextLine(), which is blocking, when sure it works and does not block.

提交回复
热议问题