Overview

Convert InputStream to String

No Comments

Because searching for “Convert InputStream to String” still brings up solutions involving StringBuffer, byte[] or something like that, developers still produce large amounts of different implementations of the same conversion in their projects. In an attempt to reduce the variations here the simplest solution using no custom code at all:

 InputStream stream = getClass().getResourceAsStream("/classpath/resource.xml");
 String xml = org.apache.commons.io.IOUtils.toString(stream);

Please spread the word, use apache commons ­čÖé

Comment

Your email address will not be published. Required fields are marked *