All I want to do is to read content from a URL into string. I don't want to pollute my code with buffered streams and loops for such a simple task. I looked into apache's HttpClient but I also don't see a one or two lines implementation...

Why not just create a utility class that encapsulates all that "polluted" buffered streams and loops? You could also use that class to handle things like the socket closing before the stream completes and to handle I/O blocks over a slow connection. After all, this is OO - encapsulate the functionality and hide it from your main class.
–
Jonathan BDec 1 '10 at 20:31

You could rename the main method to, say getText, pass URL string as a parameter and have a one-liner: String content = URLConnectionReader.getText("http://www.yahoo.com/");
–
Goran JovicDec 1 '10 at 20:27

The string will not contain any line-termination character (because of the use of BufferReader.readLine() which remove them), so it will not be exactly the content of the URL.
–
Benoît GuédasAug 21 '13 at 7:55

+1 Thanks, this worked perfectly. One line of code AND it closes the stream! Note that IOUtils.toString(URL) is deprecated. IOUtils.toString(URL url, String encoding) is preferred.
–
gmaleMay 21 '13 at 0:13