站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2SE 专题问一个简单的问题!!!

问一个简单的问题!!!

摘要: 问一个简单的问题!!!


我写了一个下载网页的程序,我运行的时候下载的中文是乱码,是不是因为big-endian和little-endian的问题,我要调整为网页原来的样子应该怎么做,难道要把每个汉字字符都手动调整吗???


把代码贴出来


import java.net.*;
import java.io.*;

public class SourceViewer2 {

public static void main (String[] args) {

if (args.length -#62; 0) {
try {
URL u = new URL(args[0]);
URLConnection uc = u.openConnection();
InputStream raw = uc.getInputStream();
InputStream buffer = new BufferedInputStream(raw);
Reader r = new InputStreamReader(buffer);
int c;
while ((c = r.read()) != -1) {
System.out.print((char) c);
}
}
catch (MalformedURLException ex) {
System.err.println(args[0] + -#34; is not a parseable URL-#34;);
}
catch (IOException ex) {
System.err.println(ex);
}

}
}

}


怎么没有人啊
up!!!


C:/Documents and Settings/Fantasy/Desktop/temp-#62;javac Test.java

C:/Documents and Settings/Fantasy/Desktop/temp-#62;java Test http://localhost:8090/i
ndex.jsp

-#60;html-#62;
-#60;head-#62;
-#60;meta http-equiv=-#34;Content-Type-#34; content=-#34;text/html; charset=gb2312-#34;-#62;
-#60;title-#62;::我顶你个肺-银行管理系统::-#60;/title-#62;
-#60;link href=-#34;CSS/mycss.css-#34; rel=-#34;stylesheet-#34; type=-#34;text/css-#34;-#62;
-#60;/head-#62;

-#60;body-#62;
-#60;table width=-#34;377-#34; height=-#34;34-#34; border=-#34;0-#34; align=-#34;center-#34; cellpadding=-#34;0-#34; cellspa
cing=-#34;0-#34;-#62;
-#60;tr-#62;
-#60;th class=-#34;bigtitle-#34;-#62;我顶你个肺-24小时自助银行-#60;/th-#62;
-#60;/tr-#62;
-#60;/table-#62;
-#60;br/-#62;
-#60;form name=-#34;form1-#34; method=-#34;post-#34; action=-#34;-#34;-#62;
-#60;table width=-#34;469-#34; height=-#34;84-#34; border=-#34;0-#34; align=-#34;center-#34; cellpadding=-#34;0-#34; cellspa
cing=-#34;0-#34;-#62;
-#60;tr-#62;
-#60;th width=-#34;178-#34; align=-#34;right-#34;-#62;帐号:-#60;/th-#62;
-#60;td width=-#34;291-#34;-#62;
-#60;input type=-#34;text-#34; name=-#34;textfield-#34;-#62; -#60;/td-#62;
-#60;/tr-#62;
-#60;tr-#62;
-#60;th align=-#34;right-#34;-#62;密码:-#60;/th-#62;
-#60;td-#62;-#60;input type=-#34;text-#34; name=-#34;textfield2-#34;-#62;-#60;/td-#62;
-#60;/tr-#62;
-#60;tr-#62;
-#60;td colspan=-#34;2-#34; align=-#34;center-#34;-#62;-#60;input type=-#34;submit-#34; value=-#34;确定-#34;-#62;
-#60;input type=-#34;reset-#34; value=-#34;重置-#34;-#62;-#60;/td-#62;
-#60;/tr-#62;
-#60;/table-#62;
-#60;/form-#62;
-#60;/body-#62;
-#60;/html-#62;

C:/Documents and Settings/Fantasy/Desktop/temp-#62;

------------------------------------为什么我没发现乱码------------


楼主可以在程序中的适当位置加上这样的代码:
(URLConnection)uc.setRequestProporty(-#34;Accept-Language-#34;,-#34;X-#34;),其中X是你想要以何种语言接收文件(各种语言字符的代号,在IE的工具中可以找到),比如说,如果你想将一个阿拉伯文的google站点的首页下载下来,而你又没写上这句(默认的是中文),那收到的就是乱码了。


mark


知道了!谢谢了
没有设置字符编码!!!


↑返回目录
前一篇: JCreator问题
后一篇: 高分诚心请教:用多个jcombobox的选项组成sql语句的查询,如何传递点击选项后的参数?不点击可以用getselecteditem,点击选项后应该用什么