全部版块 我的主页
论坛 数据科学与人工智能 IT基础 JAVA语言开发
1608 0
2015-06-05

Using a URLConnection using Java


The URLConnection class establishes a connection to a URL. The openStream( ) method of URL we used in Example 5-1 is merely a convenience method that creates a URLConnection object and calls its getInputStream( ) method. By using a URLConnection object directly instead of relying on openStream( ), you have much more control over the process of downloading the contents of a URL.

Example 5-2 is a simple program that shows how to use a URLConnection to obtain the content type, size, last-modified date, and other information about the resource referred to by a URL. If the URL uses the HTTP protocol, it also demonstrates how to use theHttpURLConnection subclass to obtain additional information about the connection.

Note the use of the java.util.Date class to convert a timestamp (a long that contains the number of milliseconds since midnight, January 1, 1970 GMT) to a human-readable date and time string.

复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群