public static String ResultToString(InputStream inputStream){
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder result = new StringBuilder();
String line = null;
try {
while((line = bufferedReader.readLine()) != null){
result.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try{
inputStreamReader.close();
inputStream.close();
bufferedReader.close();
}catch(IOException e){
e.printStackTrace();
}
}
return result.toString();
}
public static void main(String[] args) throws IOException {
URL url = new URL("http:www.baidu.com") ;
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection() ;
urlConnection.setRequestMethod("GET") ;
urlConnection.connect() ;
InputStream inputStream = urlConnection.getInputStream() ;
String result = ConvertToString(inputStream) ;
System.out.println(result);
}