[英]PrintWriter and byte[] problem
byte[] data = (byte[])opBinding.execute();
PrintWriter out = new PrintWriter(outputStream);
out.println(data);
out.flush();
out.close();
but instead of text i get @84654. 但不是文字我得到@ 84654。 How can i add byte[] to PrintWriter? 如何将byte []添加到PrintWriter? I need byte[] and not strinf becouse i have encoing problems with čćžšđ 我需要byte []而不是strinf因为我有čćžšđ的问题
您可以直接使用outputstream来写入字节。
outputStream.write(byte[] b);
PrintWriter
is meant for text data, not binary data. PrintWriter
用于文本数据,而不是二进制数据。
It sounds like you should quite possibly be converting your byte[]
to a String
, and then writing that string out - assuming the PrintWriter
you're writing to uses an encoding which supports the characters you're interested in. 听起来你很可能将你的byte[]
转换为String
,然后将该字符串写出来 - 假设您正在编写的PrintWriter
使用支持您感兴趣的字符的编码。
You'll also need to know the encoding that the original text data has been encoded in for the byte[]
, in order to successfully convert to text to start with. 您还需要知道原始文本数据已编码为byte[]
编码,以便成功转换为文本以开始。
问题是,您的代码在将结果返回到println
语句之前(隐式地)调用data.toString()
。
try this 尝试这个
byte[] data = (byte[])opBinding.execute();
PrintWriter out = new PrintWriter(outputStream);
out.println(new String(data));
out.flush();
out.close();
It worked for me.. when i used 它对我有用..当我用的时候
PrintWriter out=new PrintWriter(System.out);
Also it converts the byte data to String using toString()
method.. So it may be a reason for your encoding problem 它还使用toString()
方法将字节数据转换为String。因此,这可能是编码问题的原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.