I'm writing a small application in java
I read text files in various sizes and I need to read them line by line (and insert the line into array).
Is there difference between BufferedReader.ReadLine()
and RandomAccessFile.ReadLine()
, in terms of performance?
Is there any reason to prefer one or the other?
RandomAccessFile.readLine() might be slightly faster because it ignores character encoding. However it doesn't use buffering and still use StringBuffer :P so it could be slower on your system.
BufferedReader.readLine() is preferred because it handles character encoding e.g. UTF-8 or Windows-1252.
There is also a DataInputStream.readLine() which can be used with BufferedInputStream. Only use this is you can be sure you want ISO-8859-1 or ASCII encoding.
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