Skip to content

Instantly share code, notes, and snippets.

@deepanshumehtaa
Last active April 14, 2024 08:11
Show Gist options
  • Save deepanshumehtaa/f4dfb217a425cf2e46f887ab223431f7 to your computer and use it in GitHub Desktop.
Save deepanshumehtaa/f4dfb217a425cf2e46f887ab223431f7 to your computer and use it in GitHub Desktop.
basic Reader and Builder JAVA
InputStreamReader..............................................................................
- InputStream: class that reads binary data in the form of bytes from a source.
- InputStreamReader: It reads bytes using the given InputStream and then converts them into chars
based on a certain Charset (UTF-8, UTF-16).
- has a read() method that reads a single character (bytes --> characters)
remember:
InputStreamReader.read() != InputStream.read()
1. InputStreamReader reader = new InputStreamReader(new FileInputStream(filePath), StandardCharsets.UTF_8)
BufferedReader................................................................................
- a class which simplifies reading text from a character input stream.
- It buffers the characters in order to enable efficient reading of text data.
- buffer size of 8KB.
- it enables us to minimize the number of I/O operations by reading chunks of characters
and storing them in an internal buffer.
1. BufferedReader reader = new BufferedReader(<stream>)
2. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))
3. BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))
4. BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath))
5. BufferedReader reader = new BufferedReader(new FileReader(filePath));
reader.readLine();
reader.close();
reader.available();
reader.read(bytes);
StringBuilder...........................................................
StringBuilder sb = new StringBuilder();
sb.append(inputLine);
response = sb.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment