Byte array in  BufferedReader

Posted on 2011-03-25
Last Modified: 2012-05-11
How can i read a byte array in a Buffered Reader

    BufferedReader in = new BufferedReader(new InputStreamReader(; now is a string but it would be a byte array.
Question by:cano63
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
LVL 86

Accepted Solution

CEHJ earned 500 total points
ID: 35216483
BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(theArray)));

Open in new window


Expert Comment

ID: 35216501
You can use the toByteArray(Reader) method in the jakarta IOUtils class for this:
LVL 47

Expert Comment

ID: 35216646
And if you want to read from the SDtring as a byte array, you can do this:

BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(myString.getBytes())));

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Expert Comment

ID: 35216680
Well if it *were* a String, you'd do
BufferedReader in = new BufferedReader(new StringReader(s));

Open in new window

LVL 86

Expert Comment

ID: 35216682
(although the below would be better)
Scanner in = new Scanner(s);

Open in new window

LVL 86

Expert Comment

ID: 35217705

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question