Convert InputStream to BufferedReader in Java

Note The BufferedReader reads characters; while the InputStream is a stream of bytes. The BufferedReader can’t read the InputStream directly; So, we need to use an adapter like InputStreamReader to convert bytes to characters format. For example: // BufferedReader -> InputStreamReader -> InputStream BufferedReader br = new BufferedReader( new InputStreamReader(inputStream, StandardCharsets.UTF_8)); 1. Reads a file …

Read more

Java – How to read input from the console

In Java, there are three ways to read input from a console : System.console (JDK 1.6) Scanner (JDK 1.5) BufferedReader + InputStreamReader (Classic) 1. System.console Since JDK 1.6, the developer starts to switch to the more simple and powerful java.io.Console class. JavaConsole.java package com.mkyong.io; import java.io.Console; public class JavaConsole { public static void main(String[] args) …

Read more