我用eclipse写了个程序,下面是代码:try{
url=new URL("http://lib.verycd.com/2006/10/25/0000125301.html");
BufferedInputStream bis=new BufferedInputStream(url.openStream());
StringBuffer sb=new StringBuffer();
int i=0;
while((i=bis.read())!=-1)
{
sb.append((char)i);
}
bis.close();
return sb.toString();
}
catch(Exception e)
{
return e.getMessage();
}最后运行的结果显示乱码,我看到他网站上是用utf-8编码的,但我无论怎么转,也无法显示出正常的中文,求各位大侠帮帮忙啊!
url=new URL("http://lib.verycd.com/2006/10/25/0000125301.html");
BufferedInputStream bis=new BufferedInputStream(url.openStream());
StringBuffer sb=new StringBuffer();
int i=0;
while((i=bis.read())!=-1)
{
sb.append((char)i);
}
bis.close();
return sb.toString();
}
catch(Exception e)
{
return e.getMessage();
}最后运行的结果显示乱码,我看到他网站上是用utf-8编码的,但我无论怎么转,也无法显示出正常的中文,求各位大侠帮帮忙啊!
URL url = new java.net.URL(
"http://lib.verycd.com/2006/10/25/0000125301.html");
br = new BufferedReader(new InputStreamReader(url.openStream(),"UTF-8"));
String str;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();