用HttpURLConnection读取含日文网页出乱码,求助。 本帖最后由 fireboyz2005 于 2010-07-16 11:35:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请求返回的是html文本吧。是返回的html文本乱码还是生成出来的页面乱码?如果是返回的html文本乱码,则转换编码 public static void main(String[] args) throws IOException { URL url=new URL("http://www.yespy.net/xiaole/riwen/riwen.html"); HttpURLConnection conn=(HttpURLConnection) url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String str=null; while((str=reader.readLine())!=null){ System.out.println(new String(str.getBytes(),"GB2312")); } reader.close(); }实验下。不知道你用的是日文系统还是中文的。 谢谢closewbq,不过你的程序结果如下:<html> <head> <meta http-equiv=content-type content="text/html; charset=gb2312"> <title>test</title> </head> <body><div id="zhongwen">锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷</div><div id="riwen">锟�锟斤拷锟矫てわ拷锟斤拷锟斤拷锟捷ットわ拷_锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷巍锟�/div></body> </html> 我用的是中文系统,eclipse的项目的属性的text file encoding是utf-8 解决,用httpclien和编码GBK可以解决。 新手求助。关于类成员定义以及内存分配问题!! 再来一道题目!! 面试题 在Spring docs 的index.html内的“查找”用不了! linux中java参数空格问题 linux命令行模式下运行Java窗体 一个非常简单的问题 同一个包中的一个文件怎么不能引用另一个文件中的jLabel 啊,求助各位大哥帮帮忙,小弟的毕业设计好困难啊 怎样用RamdomAccessFile读出中文??我显示出来的都是乱码 一个符号的问题? 有转让SCJP考试卷的吗?南京的本地交易 判断字符串A中是否包含字符串B的问题,使用contains…………
public static void main(String[] args) throws IOException {
URL url=new URL("http://www.yespy.net/xiaole/riwen/riwen.html");
HttpURLConnection conn=(HttpURLConnection) url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str=null;
while((str=reader.readLine())!=null){
System.out.println(new String(str.getBytes(),"GB2312"));
}
reader.close();
}实验下。不知道你用的是日文系统还是中文的。
<head>
<meta http-equiv=content-type content="text/html; charset=gb2312">
<title>test</title>
</head>
<body>
<div id="zhongwen">锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷</div>
<div id="riwen">锟�锟斤拷锟矫てわ拷锟斤拷锟斤拷锟捷ットわ拷_锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷巍锟�/div>
</body>
</html> 我用的是中文系统,eclipse的项目的属性的text file encoding是utf-8