java network programming读书笔记(3) URL类和URI类
2011-01-03 10:58
148 查看
URL 类的java文档大概分为三部分:
1 构造URL 通过设置URL的scheme, authroity, path 等
2 当URL构造好后可以用各种getter 来获得它的各部分
3 从URL中直接得到流,下面是几种方法的详解
public final InputStream openStream( ) throws IOException
此方法得到的是原始的字节流,没有包括http协议的头。具体内容如下:
The openStream( ) method connects to the resource referenced by the URL, performs any necessary handshaking between the client and the server, and returns an InputStream from which data can be read. The data you get from this InputStream is the raw (i.e., uninterpreted) contents of the file the URL references: ASCII if you're reading an ASCII text file, raw HTML if you're reading an HTML file, binary image data if you're reading an image file, and so forth. It does not include any of the HTTP headers or any other protocol-related information. You can read from this InputStream as you would read from any other InputStream.
URLConnection getConnection()
用这个方法得到一个URLConnection连接后,就可以用URLConnection来获得相应协议的内容了,比如可以获得Http协议的头。 具体用法在以后的笔记中会提到。
public final Object getContent( ) throws IOException 这个方法的介绍看下面吧
The getContent( ) method is the third way to download data referenced by a URL. The getContent( ) method retrieves the data referenced by the URL and tries to make it into some type of object. If the URL refers to some kind of text object such as an ASCII or HTML file, the object returned is usually some sort of InputStream. If the URL refers to an image such as a GIF or a JPEG file, getContent( ) usually returns a java.awt.ImageProducer (more specifically, an instance of a class that implements the ImageProducer interface).
public final Object getContent(Class[] classes) throws IOException
返回与数组顺序对应的相应类型的类。
另外注意URLEncoder和 URLDecoder 类,它们是和字符编码相关的。
URI类的相关内容如果理解了“URI”的各个部分也就很好掌握了! 具体URI的各部分请看另一篇。
1 构造URL 通过设置URL的scheme, authroity, path 等
2 当URL构造好后可以用各种getter 来获得它的各部分
3 从URL中直接得到流,下面是几种方法的详解
public final InputStream openStream( ) throws IOException
此方法得到的是原始的字节流,没有包括http协议的头。具体内容如下:
The openStream( ) method connects to the resource referenced by the URL, performs any necessary handshaking between the client and the server, and returns an InputStream from which data can be read. The data you get from this InputStream is the raw (i.e., uninterpreted) contents of the file the URL references: ASCII if you're reading an ASCII text file, raw HTML if you're reading an HTML file, binary image data if you're reading an image file, and so forth. It does not include any of the HTTP headers or any other protocol-related information. You can read from this InputStream as you would read from any other InputStream.
URLConnection getConnection()
用这个方法得到一个URLConnection连接后,就可以用URLConnection来获得相应协议的内容了,比如可以获得Http协议的头。 具体用法在以后的笔记中会提到。
public final Object getContent( ) throws IOException 这个方法的介绍看下面吧
The getContent( ) method is the third way to download data referenced by a URL. The getContent( ) method retrieves the data referenced by the URL and tries to make it into some type of object. If the URL refers to some kind of text object such as an ASCII or HTML file, the object returned is usually some sort of InputStream. If the URL refers to an image such as a GIF or a JPEG file, getContent( ) usually returns a java.awt.ImageProducer (more specifically, an instance of a class that implements the ImageProducer interface).
public final Object getContent(Class[] classes) throws IOException
返回与数组顺序对应的相应类型的类。
另外注意URLEncoder和 URLDecoder 类,它们是和字符编码相关的。
URI类的相关内容如果理解了“URI”的各个部分也就很好掌握了! 具体URI的各部分请看另一篇。
相关文章推荐
- Java URL 类,URI类
- JAVA URL协议扩展支持HDFS
- 用java获取360doc页面上的url地址并在浏览器中自动打开
- java 从网络Url中下载文件
- JAVA使用原始HttpURLConnection发送POST数据
- java实现URL带参数请求(get/post)
- JAVA 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址
- java的web.xml中<url-pattern>配置
- java中的url 编码与解码
- java入门教程-12.2Java网络编程之统一资源定位符URL
- java根据url生成缓存key(或文件名)
- Java 利用HttpURLConnection发送http请求
- location.herf=url参数有中文传到后台java代码有乱码
- java里如何将字符转为url码 .
- 在java中获取URL的域名或IP与端口
- java设置代理访问URL
- java利用url写个抓取服务器文件
- java通过url读取文件内容示例
- java.net.URL如何通过proxy访问internet资源
- JAVA使用HttpUrlConnection实现自动上传文件