Java J2ME JSP J2EE Servlet Android

HTTP / URL Reading: Java

We can read url HTTP request in the following way efficiently.


public static String readURL(URL url) throws MalformedURLException, IOException{
String str= "";
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
str += inputLine+"\n";
in.close();
return str;
}