首页 > 代码库 > URLConnection/案例

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();
    }

}

 

URLConnection/案例