BufferedReader vs. RandomAccessFile in java

I am writing a small application in java

I read text files of different sizes, and I need to read them line by line (and insert a line into an array).
Is there a difference between BufferedReader.ReadLine() and RandomAccessFile.ReadLine() in terms of performance?

Is there any reason to prefer one or the other?

+7
source share
1 answer

RandomAccessFile.readLine () can be a little faster because it ignores character encoding. However, it does not use buffering and still uses StringBuffer: P, so it may be slower on your system.

BufferedReader.readLine () is preferred as it handles character encoding, for example. UTF-8 or Windows-1252.

There is also DataInputStream.readLine (), which can be used with BufferedInputStream. Use only this, you can be sure that you want encoding of ISO-8859-1 or ASCII.

+6
source

All Articles