Default platform's charset

Advertisement
Hi!
Does anybody know where the default platform's charset is stored? How does the JVM know what character encoding to use?
I am having problems when reading from a URLConnection.getInputStream(). More in details, I am getting an java.io.UTFDataFormatException: Invalid byte 2 of 3-byte UTF-8 sequence exception.
But if I wrap URLConnection.getInputStream() into a InputStreamReader I'm not getting this error anymore. I guess this is because a Reader object uses the default charset instead of using inputStream's charset.
Can you help me?
Thanks in advance !
Advertisement

Replay

You're correct. A Reader uses the platform default; an
InputStream uses the java default. Use Input and
OutputStreams to communicate with other java
applications. Use Readers to communicate with other
system applications.Thanks for your quick answer!
I am communicating with a local JSP. Acording to your reply, I should use a Reader because a JSP file is, in fact, a java application. But if I want to communicate with an unknown external url, I should use InputStream instead (I supose that's why the URLConnection object has a method called getInputStream() but doesn't have a getReader() method, right?)
Encoding is quite a confusing thing, isn't it? :-)
Regards.