Convert ByteArrayInputStream to String
Recently one of my friends wanted to get the string contained in a ByteArrayInputStream in Java. The method do this was bit tricky and I thought it'd be nice to share it.ByteArrayInputStream bais = // get your ByteArrayInputStream instance
int length = bais.available();
byte [] buff = new byte[length];
bais.read(buff);
That's it!!
Subscribe to:
Post Comments
(
Atom
)
:) Nice, save my time with this :).
ReplyDelete