Tutorialspoint examples

Learn java tutorial with examples for beginners online

convert byte array to bufferedreader java program


Example:

package com.tutorialspointexamples;
 
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
 
public class ByteArrayToBufferedReader {
  public static void main(String args[]){
	  String str = "Test Content";
	  byte[] content = str.getBytes();
	  InputStream is = null;
	  BufferedReader bfReader = null;
	  try {
	    is = new ByteArrayInputStream(content);
	    bfReader = new BufferedReader(new InputStreamReader(is));
	    String temp = null;
	    while((temp = bfReader.readLine()) != null){
	      System.out.println(temp);
	    }
	  } catch (Exception e) {
          e.printStackTrace();
      } 
  }
}

Output:

Test Content

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status