By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,236 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,236 IT Pros & Developers. It's quick & easy.

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

P: 1
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?fuseaction=user.viewprofile&friendid =29422575". All the alternatives that I've found have not solved this problem. This is my java code:
Expand|Select|Wrap|Line Numbers
  1.  public static void main(String[] args) throws Exception {
  2.         // TODO code application logic here
  3.         String _url = "http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=29422575";
  4.         BufferedReader reader = null;
  5.         try {
  6.             URL url = new URL(_url);
  7.             URLConnection urlConnection = url.openConnection();
  8.             reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
  9.             StringBuilder sb = new StringBuilder();
  10.             String line = null;
  11.  
  12.  
  13.  
  14.             while ((line = reader.readLine()) != null) {
  15.                 sb.append(line);
  16.                 sb.append("\n");
  17.                 System.out.println(line);
  18.             }
  19. //            System.out.println(sb.toString());
  20.         } catch (Exception ex) {
  21.             ex.printStackTrace();
  22.  
  23.         }
  24.  
  25.     }
  26.  
thanks a lot in advance , anyone...?
Mar 27 '12 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
You can check id reading will block by calling BufferedReader.ready
Mar 28 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.