encodings

Hallo,

I'm reading from a URL class as shown here:

http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html

however, if site is in cyrillic (or other non-english language) what i get is a lot of ? question marks, or sometimes other strange symbols. what should i do to display it correctly ?

thanks.

[346 byte] By [invinatea] at [2007-11-27 1:57:06]
# 1

use the constructor for String (charsetName="UTF-8"):

String

public String(byte[] bytes,

String charsetName)

throws UnsupportedEncodingException

Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required.

Parameters:

bytes - the bytes to be decoded into characters

charsetName - the name of a supported charset

Throws:

UnsupportedEncodingException - If the named charset is not supported

Since:

JDK1.1

swolanya at 2007-7-12 1:32:17 > top of Java-index,Core,Core APIs...