2

我尝试从网页阅读整个源代码,但我只收到一半或更少。我的代码有问题吗?

这是我写的代码:

public class ReadFromReuters {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    ReadFromReuters rfr = new ReadFromReuters();
    try(BufferedReader br = new BufferedReader(new InputStreamReader(rfr.getConnection().getInputStream()))){
        String str;
        while((str = br.readLine()) != null){                
            System.out.println(str);
        }
    }catch(IOException ioe){}         
}
public URLConnection getConnection() throws MalformedURLException, IOException{
    URL reuters = new URL("http://www.quickflix.com.au/browse/play");
    URLConnection conn = reuters.openConnection();        
    return conn;
}
public void splitBy(String str){

}
}    
4

2 回答 2

0

我尝试了您的代码并纠正了一些错误,它工作正常。试试这个修改后的代码。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class ReadFromReuters {

    public static void main(String[] args) {

        // TODO code application logic here
        ReadFromReuters rfr = new ReadFromReuters();
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(rfr.getConnection().getInputStream()));
            String str;
            while((str = br.readLine()) != null){                
                System.out.println(str);
            }
        }catch(IOException ioe){}         
    }

    public URLConnection getConnection() throws MalformedURLException,
            IOException {
        URL reuters = new URL("http://www.quickflix.com.au/browse/play");
        URLConnection conn = reuters.openConnection();
        return conn;
    }

    public void splitBy(String str) {

    }

}
于 2013-10-22T18:44:40.510 回答
0

测试了你的代码。似乎工作。我已经将您的代码输出和站点的源代码与 WinMerge 进行了比较。结果:没有差异。注意:本站使用分页!您只能获得带有此代码的第一页。

于 2013-10-22T18:13:25.613 回答