验证中...
7.21 杭州源创会火热报名中,一起来看看移动开发如何紧跟浪潮?
语言: Java
分类: 编程语言基础
最后更新于 2018-05-17 13:11
gistfile1.txt
原始数据 复制代码
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
public class baidu {
public static void main(String[] args) {
try {
URL url=new URL("http://pic26.photophoto.cn/20130218/0036036878180433_b.jpg");
url.openConnection();
URLConnection urlConnection = url.openConnection();
HttpURLConnection connection = (HttpURLConnection) urlConnection;
DataInputStream is=new DataInputStream(connection.getInputStream());
OutputStream os=new FileOutputStream("C:/a.jpg");
byte [] b=new byte[1024];
int len=-1;
while ((len = is.read(b)) > 0) {
os.write(b, 0, len);
}
os.write(b,0,b.length);
os.flush();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

评论列表( 0 )

你可以在登录后,发表评论