在读取的时候,不能将htm标签读取出来。
如:<h1>hello,world!</h1>
读取出 hello,world!我是想先判断每行中<和>,然后将<和>中的内容跳过不读取,但是用skip好象不好怎么跳,并且这种方法也有很多其它的缺陷。
请哪位给个大概读取html文件的内容思路。

解决方案 »

  1.   

    孙鑫老师的,你看看有用没得?
    import java.net.*;
    import java.io.*;
    import java.util.*;
    //import java.lang.*;
    public class GetGoogle{
    public static void main(String[] args)throws Exception{
    System.out.println("获取日文页面");
    getContentByLanguage("ja");
    System.out.println("\n");
    System.out.println("获取中文页面");
    getContentByLanguage("zh-cn");
    System.out.println("\n");
    }
    public static void getContentByLanguage(String country) throws Exception{
    URL urlGoogle=new URL("http://www.google.cn");
    HttpURLConnection googleConnection=(HttpURLConnection)urlGoogle.openConnection();
    googleConnection.setRequestProperty("Accept-Language",country); Map requests=googleConnection.getRequestProperties();
    Set reqFields=requests.keySet();
    Iterator itrReq=reqFields.iterator();
    while(itrReq.hasNext()){
    String Field=(String)itrReq.next();
    System.out.println(Field + ":" +googleConnection.getRequestProperty(Field));

    }
    googleConnection.connect();
    Map responses=googleConnection.getHeaderFields();
    Set resFields=responses.keySet();
    Iterator itrRes=resFields.iterator();
    while(itrRes.hasNext()){
    String Field=(String)itrRes.next();
    System.out.println(Field + ":" +googleConnection.getHeaderField(Field));
    }
    InputStream iss=googleConnection.getInputStream();
    BufferedReader br=new BufferedReader(new InputStreamReader(iss));
    String strLine=null;
    while((strLine=br.readLine())!=null){
    System.out.println(strLine);
    }
    br.close();
    googleConnection.disconnect();
    }
    }
      

  2.   

    只要设置了URL就能把HTML中的内容读取出来...