You are browsing the archive for ByteArrayInputStream.

Java Converting String to InputStream

March 11, 2012 in Java

This is the short tip of the day, this tip can be helpful to you if you are wishing, for example, to parse an XML String using the Java DOM APIs or in general if you are working with an API that does not expose an interface to accept the content as a String and it exposes an interface that accepts an input stream.

Using the class you can convert a String object to a byte array input stream as follows:

InputStream istream = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
Skip to toolbar