As title say …
I read content from htto response
InputStream is = response.getEntity().getContent();
String cw = IOUtils.toString(is);
byte[] b = cw.getBytes("Cp1250");
String x = StringUtils.newStringUtf8(b);
String content = new String(b, "UTF-8");
System.out.println(content);
I have tried plenty of variations. I am little confused about what are correct encoding constants used as strings. windows-1250 or Cp1250. UTF-8 or utf-8 or utf8?
You seem to think that a
Stringobject has an encoding. That’s not correct. An encoding is used as part of the translation from binary data (abyte[]orInputStream) to text data (aStringorchar[]etc).It’s not clear what
IOUtils.toStringis doing, but it’s almost certainly losing data or at least handling it inappropriately. If your data is originally in Windows-1250, then you should use anInputStreamReaderwrapping theInputStream, specifying the charset in theInputStreamReaderconstructor call.It’s not clear where UTF-8 comes in – you might want to write out the data in UTF-8 afterwards, but the result of that would be
byte[], not a string.