Mostly technical stuff with some interesting moments of life

Convert ByteArrayInputStream to String

1 comment
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];;

That's it!!

1 comment :