URLConnection案例

package zuihou;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class DownLoad {
    public static void main(String[] args) throws IOException {
        
URL url=new URL("http://588ku.com/banner/4694318.html");
URLConnection conn=url.openConnection();
InputStream is=conn.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(is));
//FileOutputStream fos=new FileOutputStream("d:/abc.html");
//byte[]b=new byte[100];
//int i=-1;
//while((i=is.read(b))!=-1){
//    fos.write(b,0,i);
//}
//fos.close();

String str=null;
while((str=br.readLine())!=null){
    System.out.println(str);
}
is.close();
    }

}

 

posted @ 2017-05-14 14:36  苏轼的红烧肉  阅读(150)  评论(0编辑  收藏  举报