?
Solved

Byte array in  BufferedReader

Posted on 2011-03-25
6
Medium Priority
?
1,286 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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