+ 9

(SOLVED) Java: FileReader vs. Scanner

If we have Scanner, why would we read file with FileReader?

22nd Aug 2021, 12:53 PM
🇺🇦 GUMBALL 🇺🇦 [Dead account]
3 ответов
+ 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
22nd Aug 2021, 1:28 PM
Tibor Santa
Tibor Santa - avatar
+ 7
Thanks!
22nd Aug 2021, 1:31 PM
🇺🇦 GUMBALL 🇺🇦 [Dead account]