显示文本内容,直接用FileInputStream读取,然后显示在JTextArea()就行了。
显示网页内容,用JEditorPane,相当于一个小型浏览器!

解决方案 »

  1.   

    看看javax.swing.text.html 这个包下面的冬冬
      

  2.   

    我是这么写的,不过url老是出错,为什么?
        URL url = null;
        String path = null;
        try {
            path = "C:/readme.htm";
            url = getClass().getResource(path);
        } catch (Exception e) {
            System.err.println("Failed to open " + path);
            url = null;
        }
        if(url != null)
          htmlPane.setPage(url);  }
      

  3.   

    不明白你是不是要读取html文本吗?我这里倒是有一个。
    urlsource 为http地址。filename为保存文件名。
    public void fsave(String urlsource,File filename)
    { netsocket=true;
    try
    {
    URL url = new URL(urlsource);
    HttpURLConnection urlConn= (HttpURLConnection)url.openConnection();
    InputStream in=url.openStream();
    if (urlConn.getResponseMessage().equals("OK"))
    {
    int b;
    int bt=0;
    FileOutputStream cf = new FileOutputStream(filename);
    while ((b=in.read())!=-1 && bt<=100000)
    { cf.write(b);
    bt++;
    }
    cf.close();
    writeLog("总字节数为:"+bt);
    }
    in.close();
    }
    catch (IOException exception)
    { writeLog("fsave file Error: " + exception);
    netsocket=false;
    }
    }
    如果是要用java做IE浏览器似的冬冬,我就不懂了。