URLConnection sapmle

 

1.  URL->URLConnection

2.  BufferedInputStream

3.  BufferedOutputStream

String apikey = "abcde12345";
String url = "http://www.digg.com";

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&url=" + url + "&userpass=htm2pdf");
URLConnection uc = u.openConnection();

BufferedInputStream is = new BufferedInputStream(uc.getInputStream());
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(outs));

byte[] b = new byte[8 * 1024];
int read = 0;
while ((read = is.read(b)) > -1) {
    bout.write(b, 0, read);
}

bout.flush();
bout.close();
is.close();

 

猜你喜欢

转载自just2learn.iteye.com/blog/2041084