Java Scanner with InputStream not working

后端 未结 2 2048
终归单人心
终归单人心 2021-01-28 22:51

I am reading an InputStream (fis) from a source and on which I have to do some multiple search. I am using Scanner class and I instantiate it after every search. But it works on

2条回答
  •  青春惊慌失措
    2021-01-28 23:19

    Create just one Scanner, and reuse it each time. The problem is happening because the BufferedReader *buffers* your input -- which means that it reads more than it needs and stores it up for later. When you create your second scanner, all the input has already been grabbed by the firstBufferedReader`, leaving nothing left to scan.

提交回复
热议问题