Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://java.sun.com/javase/6/docs/api/java/io/Writer.html" rel="nofollow noreferrer"><code>Writer</code></a> objects (including <a href="http://java.sun.com/javase/6/docs/api/java/io/PrintWriter.html" rel="nofollow noreferrer"><code>PrintWriter</code></a>) are intended specifically for output of character data. It sounds like you want an <a href="http://java.sun.com/javase/6/docs/api/java/io/OutputStream.html" rel="nofollow noreferrer"><code>OutputStream</code></a> instead of a <code>Writer</code> here.</p> <p>Where did your <code>PrintWriter</code> come from? If it was created by wrapping some kind of <code>OutputStream</code> with an <code>OutputStreamWriter</code> and then wrapping that with a <code>PrintWriter</code>, then you should just use the original <code>write(byte[] b)</code> method from the original <code>OutputStream</code>, rather than trying to use a <code>Writer</code>.</p> <p>If you want to mix character output and byte output, you may need to use <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html#getBytes%28java.lang.String%29" rel="nofollow noreferrer"><code>String.getBytes()</code></a>. Check out this example:</p> <pre><code>OutputStream o = this.conn.getOutputStream(); // Based on your comment String s = "Hello, world!"; byte[] b = ...; // These are the raw bytes that you want to write o.write(s.getBytes("UTF-8")); o.write(b); </code></pre> <p>(Of course, this will only work if the system that is reading your output understands that you are writing a mixture of characters and raw bytes and knows how to handle the mixed data that you are sending it.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload