//用这个试试。
import java.io.*; 
import java.net.*; public class showfile2 { 
    public showfile2(){
    }
     
    public static void main(String args[]){ 
       InputStream filecon = null; 
       DataInputStream filedata = null; 
       String fileline; 
       String url = "http://www.csdn.net/expert/topic/143/143518.shtm"; 
       URL fileur; 
       try { 
             fileur = new URL(url); 
             filecon = fileur.openStream(); 
             filedata = new DataInputStream(filecon); 
             while ((fileline = filedata.readLine()) != null) { 
                    byte b[]=fileline.getBytes("ISO8859_1");
                    System.out.println(new String(b,"GB2312")); 
             } 
       } 
       catch (IOException e) { System.out.println("Error in I/O:"); 
       } 
   } 

解决方案 »

  1.   

    bootcool(bootcool)这位仁兄,非常感谢,希望你能讲讲下面的这段程序,可以吗?先谢了

          try { 
                fileur = new URL(url); 
                filecon = fileur.openStream(); 
                filedata = new DataInputStream(filecon); 
                while ((fileline = filedata.readLine()) != null) { 
                        byte b[]=fileline.getBytes("ISO8859_1");
                        System.out.println(new String(b,"GB2312")); 
                } 
          } 
          catch (IOException e) { System.out.println("Error in I/O:"); 
          }  
      

  2.   

    fileur = new URL(url);是指以url字符串所代表的url地址,创建一个URL对象。
    filecon = fileur.openStream(); 对URL对象打开一个连接,并且放回一个流以便读取该连接。
    filedata = new DataInputStream(filecon); 创建一个数据输入流从上面的那个输入流读取数据。            while ((fileline = filedata.readLine()) != null) { 
                        byte b[]=fileline.getBytes("ISO8859_1");
                        System.out.println(new String(b,"GB2312")); 
                } 
    一行行的读直到数据结束。结束时以null表示。
    由于java的中文问题,每次读入的一行都必须按iso88951的格式送到一个byte数组中,然后:Allocates a new String containg characters constructed from an array of 8-bit integer values. Each character c in the resulting string is constructed from the corresponding component b in the byte array such that c == (char)(((hibyte & 0xff) << 8)
    | (b & 0xff)) Parameters: 
    ascii - the bytes to be converted to characters 
    hibyte - the top 8 bits of each 16-bit Unicode character。具体的java中文处理和unicode问题可以在论坛搜一下。