Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scanner constructor causes bufferedReader to return null

Im trying to do -

BufferedReader br = new BuffereReader(file);
Scanner s = new Scanner(br);
sys.out(s.next());
sys.out(buffReader.readLine());

What I expect to happen is to now have 2 separate readers on the file pointing at different places. However, the buffReader returns null on the readLine, while the scanner seems to work fine. Is it possible for me to have 2 readers like I want?

like image 949
David says Reinstate Monica Avatar asked Nov 04 '22 08:11

David says Reinstate Monica


1 Answers

What I expect to happen is to now have 2 separate readers on the file pointing at different places.

Your expectation is misplaced. In the first place, both are connected to the same underlying file, which only has one current position. In the second place, the Scanner is wrapped around the BufferedReader, so any change in the position causes by the Scanner happens via the BufferedReader.

like image 129
user207421 Avatar answered Nov 08 '22 04:11

user207421