How do I turn a String into a InputStreamReader in java?

Yossale picture Yossale · Oct 29, 2008 · Viewed 173k times · Source

How can I transform a String value into an InputStreamReader?

Answer

Guido picture Guido · Oct 29, 2008

ByteArrayInputStream also does the trick:

InputStream is = new ByteArrayInputStream( myString.getBytes( charset ) );

Then convert to reader:

InputStreamReader reader = new InputStreamReader(is);