I have to read txt files in my program. Im currently using FileReader and BufferedReader. I tried to use Scanner but its slower than FileReader and BufferedReader. Is there any class, which can read files faster ? It must be written in Java Language.
I need to read all words(strings splited by white space) from text file
Assuming you read all the file in memory, the fastest, from a code writing perspective, is:
List<String> lines = Files.readAllLines(yourFile, charset);
I would expect performance, from an execution perspective, to be as good if not better (this has supposedly been optimised by the team who wrote it).
You can then split or do whatever you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With