Urltest.java
资源名称:MY_PAPA.rar [点击查看]
上传用户:xie_wn
上传日期:2022-03-04
资源大小:941k
文件大小:1k
源码类别:
网络截获/分析
开发平台:
Java
- package com.url;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class Urltest {
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- URL url=new URL("http://sports.tom.com/uimg/2009/7/27/dongsheng/1248654595671_7033.jpg");
- InputStream in=url.openConnection().getInputStream();
- FileOutputStream out=new FileOutputStream("1.jpg");
- byte[] b=new byte[1024*5];
- int length=0;
- while((length=in.read(b))!=-1)
- {
- out.write(b, 0, length);
- }
- out.flush();
- in.close();
- out.close();
- }
- }