Following code gets the character set from a website.
String encoding="";
URL u = new URL("http://www.msn.com");
URLConnection uc = u.openConnection( );
String contentType = uc.getContentType( );
int encodingStart = contentType.indexOf("charset=");
if (encodingStart != -1) {
encoding = contentType.substring(encodingStart+8);
}
System.out.println(encoding);
Output: