Writer对象(包括
PrintWriter)专门用于输出字符数据。听起来您想要这里
OutputStream而不是
Writer这里。
你
PrintWriter是哪里人 如果它是通过将某种形式
OutputStream的“
OutputStreamWriter和”换成“然后再用”包裹而成的
PrintWriter,那么您应该使用原始的原始
write(byte[]b)方法
OutputStream,而不是尝试使用
Writer。
如果要混合使用字符输出和字节输出,则可能需要使用
String.getBytes()。看看这个例子:
OutputStream o = this.conn.getOutputStream(); // based on your commentString s = "Hello, world!";byte[] b = ...; // These are the raw bytes that you want to writeo.write(s.getBytes("UTF-8"));o.write(b);(当然,只有在读取输出的系统知道您正在写入字符和原始字节的混合并且知道如何处理发送的混合数据时,这才起作用。)



