Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Byte array in  BufferedReader

Posted on 2011-03-25
6
Medium Priority
?
1,299 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.
Suggested Courses

618 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