Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1329
  • Last Modified:

Byte array in BufferedReader

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
cano63
Asked:
cano63
  • 4
1 Solution
 
CEHJCommented:
Use
BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(theArray)));

Open in new window

0
 
colr__Commented:
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
 
for_yanCommented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Open in new window

0
 
CEHJCommented:
(although the below would be better)
Scanner in = new Scanner(s);

Open in new window

0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now