Wednesday, 29 July 2015

Buffer Reader and Scanner class

Topics

1.  Introduction to Buffer Reader and Scanner class.

Buffered Reader class can be used to read data line by line by readLine() method.

  1. BufferedReader has significantly larger buffer memory than Scanner. Use BufferedReader if you want to get long strings from a stream, and use Scanner if you want to parse specific type of token from a stream
  1. Scanner can use tokenize using custom delimiter and parse the stream into primitive types of data, while BufferedReader can only read and store String.
  1. BufferedReader is synchronous while Scanner is not. Use BufferedReader if you're working with multiple threads




Image result for Buffer Reader and Scanner class in java





Image result for Buffer Reader and Scanner class in java



2. difference between Buffer Reader and Scanner class



BufferedReader Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.


Where Scanner is a simple text scanner which can parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.

No comments:

Post a Comment