BufferedReader.read() blocks,when checking if there's any input for some URLs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redateksystem
    New Member
    • Mar 2012
    • 1

    BufferedReader.read() blocks,when checking if there's any input for some URLs

    Hi everyone ,

    i have the following problem :
    I am working on an application that index web pages. When i read the content of some URLs, BufferedReader. read() blocks, e.g. "http://profile.myspace .com/index.cfm?fusea ction=user.view profile&fri endid=29422575" . All the alternatives that I've found have not solved this problem. This is my java code:
    Code:
     public static void main(String[] args) throws Exception {
            // TODO code application logic here
            String _url = "http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=29422575";
            BufferedReader reader = null;
            try {
                URL url = new URL(_url);
                URLConnection urlConnection = url.openConnection();
                reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                StringBuilder sb = new StringBuilder();
                String line = null;
    
    
    
                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                    sb.append("\n");
                    System.out.println(line);
                }
    //            System.out.println(sb.toString());
            } catch (Exception ex) {
                ex.printStackTrace();
    
            }
    
        }
    thanks a lot in advance , anyone...?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You can check id reading will block by calling BufferedReader. ready

    Comment

    Working...