Are these solutions the same? If not, how do they differ?
Are these solutions the same?
Dyskutowane
Komentarze (1)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Thomas
6 sierpnia 2022, 17:46
your solution acesses the hard drive, reads a byte, does some business logic (here just the output) and repeats. That's a lot of stress for the io and blocking it. Usually you try to buffer reads and writes and avoid calculations with the read data. The CG solution is on a good track. It adds all read data to a StringBuilder (just collecting the data) and does the logic later (the output). The Scanner however may not be the best decision as it may or may not buffer input (at least that's what the api docs say: ...it may buffer all of the input...)
I'd go for a buffered stream or use an array to buffer the input. But there are countless ways to code a solution for that.
0