URL
来源:互联网 发布:阿里云ace下线原因 编辑:程序博客网 时间:2024/05/29 02:13
网址
package com.lingzhuo.url;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.MalformedURLException;import java.net.URL;public class BaiduUrl { public static void main(String[] args) { try { URL url=new URL("http://www.baidu.com/"); InputStream is=url.openStream(); BufferedReader br=new BufferedReader(new InputStreamReader(is)); String line=br.readLine(); if(line!=null){ System.out.println(line); line=br.readLine(); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
图片
package com.lingzhuo.url;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.MalformedURLException;import java.net.URL;public class ImgUrl { public static void main(String[] args) { OutputStream os = null; File file = new File("d:\\img.jpg"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { os = new FileOutputStream(file); URL url = new URL( "http://h.hiphotos.baidu.com/image/pic/item/f9dcd100baa1cd119d029327bb12c8fcc3ce2d05.jpg"); InputStream is = url.openStream(); byte[] array = new byte[1024]; int i = is.read(array); while (i != -1) { os.write(array, 0, i); i = is.read(array); } os.flush(); is.close(); os.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
0 0
- url
- URL
- URL
- url
- url
- URL
- url
- URL
- url
- url
- url
- URL
- Url
- url
- URL
- URL
- url
- URL
- logistic回归与牛顿方法的python实现 (standford公开课程小作业)
- 黑马程序员---iOS基础---协议
- UITextField总结
- Java删除ArrayList中的重复元素的2种方法
- poj 1222 高斯消元详解
- URL
- Swap Nodes in Pairs
- 数据源架构模式之行入口模式
- webkit编译
- php模拟post请求发送文件
- 深度学习的"非主流"应用
- Android之Inflate()方法用途
- hdu1716(排列2)
- 程序的运算符与表达式