Thursday 13 May 2010

String to an Input Stream

Recently I came across an issue in java where xml data retrieved from a database. The returned string needs to be converted into an input stream to be useful in the program.

The following is a solution I used; you may find it useful. I have used UTF-8 encoding as it was required for my case, altername as required.

InputStream is = new ByteArrayInputStream (myXMLString.getBytes ("UTF-8"));