0

While practising file I/O in Java, I came across an assignment where I has to rewrite a method that looks up what recorddata is associated with a given record ID. Now, the method I'm talking about is using a FileReader wrapped in a BufferedReader in order to read the characters. Oddly enough, the assignment itself suggests that using a BufferedStreamReader(?) might not be the most efficient way of retrieving characters from a file. I find this even more confusing considering the method contains a BufferedReader instead of a BufferedStreamReader.

So my question is, isn't using a BufferedReader wrapper for a FileReader already the most efficient (in terms of speed) way to read characters in a file?

EDIT: The assignment talks of a BufferedStreamReader, not a BufferedInputStream

Anubis
  • 1,162
  • 4
  • 14
  • 31
  • possible duplicate of [What is the quickest / most efficient way to append a char to a file loaded into memory?](http://stackoverflow.com/questions/10268654/what-is-the-quickest-most-efficient-way-to-append-a-char-to-a-file-loaded-into) – wchargin May 09 '13 at 17:44

2 Answers2

0

I haven't come accross the BufferedStreamReader But would read Characters Using BufferedReader First Into String and then Character By character if That is what you are talking about.

            FileInputStream fs = new FileInputStream(filename);
            BufferedReader br = new BufferedReader(new InputStreamReader(fs));
            for (int j = 0; j < 0; j++) {//The the first Line
            String str = br.readLine().trim();
            char[] chars = str.toCharArray();
            String first = String.valueOf(chars[0]);//The first character
            String second = String.valueOf(chars[1]);//The second

            }
Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
-1

A Reader reads characters from a InputStream. Hence it would be the best to buffer the actual file system access, here the BufferedInputStream, because that is what can be slow.

Mot
  • 28,248
  • 23
  • 84
  • 121