String sTmp="http://www.csdn.net";
try{
URL url=new URL(sTmp); HttpURLConnection connect =(HttpURLConnection) url.openConnection();
connect.setDoInput(true);BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream())); String line = null;
StringBuffer content= new StringBuffer();while((line = in.readLine()) != null){//line为返回值,这就可以判断是否成功、content.append(line);
}in.close() ;
in=null;
url=null;
String msg = content.toString();
System.err.println(msg);
}catch(IOException ex){
ex.printStackTrace();
}catch(Exception e){System.out.println("错误:");
System.out.println(e.getStackTrace());}}
try{
URL url=new URL(sTmp); HttpURLConnection connect =(HttpURLConnection) url.openConnection();
connect.setDoInput(true);BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream())); String line = null;
StringBuffer content= new StringBuffer();while((line = in.readLine()) != null){//line为返回值,这就可以判断是否成功、content.append(line);
}in.close() ;
in=null;
url=null;
String msg = content.toString();
System.err.println(msg);
}catch(IOException ex){
ex.printStackTrace();
}catch(Exception e){System.out.println("错误:");
System.out.println(e.getStackTrace());}}
调用url.openStream(),返回的是一 InputStream 对象,然后用inputStream 去读
这样的话
Sokcet socket = new Socket("www.xxx.com",80);
PrintWriter put = new PrintWriter(Socket.getOutputStream(),true);
put.println("Get http://www.xxx.com/xxxx.htm ;HTTP/1.0");
put.println();
就可以用socket.getInputStream()得到读入流了.