snipt

Ctrl+h for KB shortcuts

Java

Stream to String

1
2
3
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
https://snipt.net/embed/14f145a3a5201607e38146e124cf6585/
/raw/14f145a3a5201607e38146e124cf6585/
14f145a3a5201607e38146e124cf6585
java
Java
3
2019-05-23T01:35:17
True
False
False
/api/public/snipt/40663/
stream-to-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">StringWriter</span> <span class="n">writer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">StringWriter</span><span class="o">();</span> </span><span id="L-2"><a name="L-2"></a><span class="n">IOUtils</span><span class="o">.</span><span class="na">copy</span><span class="o">(</span><span class="n">inputStream</span><span class="o">,</span> <span class="n">writer</span><span class="o">,</span> <span class="n">encoding</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a><span class="n">String</span> <span class="n">theString</span> <span class="o">=</span> <span class="n">writer</span><span class="o">.</span><span class="na">toString</span><span class="o">();</span> </span></pre></div> </td></tr></table>
java, servlet, stream, string, tomcat