Results 1 to 2 of 2
  1. #1
    theChameleon is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default downloadWebpage() problem

    im trying to build a custom webpage + RSS reader from scratch.

    the method shown below works for the most part. but it will always get this Exception "java.net.SocketException: Unexpected end of file from server" whenever a RSS is from "www.nyaatorrents.org".

    but, when i open a RSS using RssReader, it works. so, what am i missing here?

    Java Code:
    	public static String downloadWebpage(final String urlString) {
    		URL url;
    		InputStream is = null;
    		DataInputStream dis;
    		String line;
    		StringBuffer buffer = new StringBuffer();
    
    		try {
    			url = new URL(urlString);
    			is = url.openStream();  // throws an IOException
    			dis = new DataInputStream(new BufferedInputStream(is));
    			while ((line = dis.readLine()) != null) {
    				buffer.append(line + "\n");
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				is.close();
    			} catch (Exception err) {}
    			finally{
    				return buffer.toString();
    			}
    		}
    	}

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,432
    Blog Entries
    7
    Rep Power
    20

    Default

    Have you read what the API documentation has to say about the DataInputStream.readLine() method? Why not use a BufferedReader instead?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •