Resetting a .nextLine() Scanner

后端 未结 5 466
生来不讨喜
生来不讨喜 2020-12-03 17:42

I am a rank amateur when it comes to Java, so please pardon my question if it seems dumb :-P I have the following code which is designed to count the number of lines in a f

5条回答
  •  再見小時候
    2020-12-03 18:18

    This is impossible to do.

    The reason to not include it, is the wide range of input types it supports. One example is streams. These don't store the results after they have been passed on, so they don't support resetting.

    So the elegant way is to create a new Scanner. If you give it many custom settings, create a factory method.

提交回复
热议问题