Solved

Byte array in  BufferedReader

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

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));


system.in now is a string but it would be a byte array.
0
Comment
Question by:cano63
[X]
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
6 Comments
 
LVL 86

Accepted Solution

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

Open in new window

0
 
LVL 8

Expert Comment

by:colr__
ID: 35216501
You can use the toByteArray(Reader) method in the jakarta IOUtils class for this:
http://commons.apache.org/io/api-1.4/org/apache/commons/io/IOUtils.html
0
 
LVL 47

Expert Comment

by:for_yan
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())));

0
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

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

Open in new window

0
 
LVL 86

Expert Comment

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

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35217705
:)
0

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