我在写个小程序,需要过去网页代码的,我是菜鸟,请问我这个代码好吗?有不足的请指出!~~import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Scanner;public class URLReader
{
public static void main(String args[])
{
try
{
URL tirc = new URL("http://www.kkkmh.com/manhua/0609/mxo-mo-fa-xing-hui-mo-ai.html");
Scanner scan = new Scanner(tirc.openStream());
System.out.println(tirc.getHost());
while (scan.hasNext())
{                             
System.out.println(scan.next().replace("\\/", "/"));
}
}
catch (IOException e)
{
System.out.println(e);
}
} public static String china(String args)
throws UnsupportedEncodingException
{
String s = null;
s = new String(args.getBytes("UTF-8"), "Unicode");
return s;
            
}}

解决方案 »

  1.   


     Scanner scan = new Scanner(tirc.openStream(),"UTF-8")改成這樣就可以了
      

  2.   


    /** */
    /**
     * 读取一个网页全部内容
     */
    public String getOneHtml(String htmlurl) throws Exception {
    URL url;
    String temp;
    StringBuffer sb = new StringBuffer(); url = new URL(htmlurl);
    BufferedReader in = new BufferedReader(new InputStreamReader(url
    .openStream(), "utf-8"));// 读取网页全部内容
    while ((temp = in.readLine()) != null) {
    sb.append(temp);
    }
    in.close();
    return sb.toString();
    }
      

  3.   

    Scanner scan = new Scanner(tirc.openStream(),"UTF-8")
      

  4.   

    Java code
        /** */
        /**
         * 读取一个网页全部内容
         */
        public void getOneHtml(String htmlurl) throws Exception {
            URL url;
            String temp;
            PrintWrite out =new PrintWrite(new File("D:/default.html"));
            url = new URL(htmlurl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url
                    .openStream(), "utf-8"));// 读取网页全部内容
            while ((temp = in.readLine()) != null) {
                out.println(temp);
            }
            out.flush();
            out.close();
            in.close();
           }我写的事D:/default.html
    你可以随便制定路径
      

  5.   

    ,,这样也是有问题的,要看你访问网址的项目是放在什么服务器上的,如果服务器的编码是UTF8,那么在程序里面解析的时候就得用UTF8,在windows下,就得用GBK了。