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
  • 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())));

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project error 5 56
jar file executable 12 52
HashTable highest marks enumeration alternative 9 39
Tomcat: Unable to run tomcat service. 2 20
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

810 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