+ 9
(SOLVED) Java: FileReader vs. Scanner
If we have Scanner, why would we read file with FileReader?
3 Antworten
+ 2
FileReader is a very low level API that can only read a single character at a time, that's why most commonly it is wrapped inside a BufferedReader, which also add some convenience, e.g. reading whole lines at a time.
Scanner is typically slower than BufferedReader because it uses regular expressions to parse the text.
https://medium.com/@isaacjumba/why-use-bufferedreader-and-bufferedwriter-classses-in-java-39074ee1a966
However if you need to work with files, I really recommend to check out the more modern java.nio.file API, which is the best way to process files in Java.
https://www.baeldung.com/java-nio-2-file-api
+ 7
Thanks!