URLConnection/案例
阿新 • • 發佈:2017-05-14
str close exceptio lin () rgs enc pack []
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 staticvoid 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/案例