静止的流水的学习日志
静止的流水
全部博文(210)
Windows(1)
Linux(31)
2011年(34)
2010年(121)
2009年(37)
2008年(18)
cynthia
wojiuzhu
jd_lzh
鄙人姓王
Jack_Tan
fanbiubi
猜我咯
aaccp1
chrisy52
分类: Java
2009-08-20 10:35:37
package test;import java.net.URL;import java.net.HttpURLConnection;import java.net.URLConnection;import java.util.Date;/** * URL测试程序 * @author 静止的流水 * */public class GetUrlInfor{ private static String url; /** * 构造函数 * @param s */ public GetUrlInfor(String s) { url = s; } /** * 单行打印 * @param s */ private static void print(String s) { System.out.println(s); } /** * 打印函数 * @throws Exception */ public void printinfor()throws Exception { URL urlnew = new URL(url); print("协议 = "+urlnew.getProtocol()); print("主机地址 = "+urlnew.getHost()); print("文件名 = "+urlnew.getFile()); print("端口 = "+urlnew.getPort()); URLConnection newconnection = urlnew.openConnection(); newconnection.connect(); print(newconnection.getContentEncoding()); print(newconnection.getContentType()); print(String.valueOf((newconnection.getContentLength()))); print(newconnection.getContent().toString()); print(new Date(newconnection.getLastModified()).toString()); if(newconnection instanceof HttpURLConnection) { HttpURLConnection h = (HttpURLConnection) newconnection; print(h.getRequestMethod()); print(h.getResponseMessage()); print(String.valueOf(h.getResponseCode())); } } /** * 主函数 * @param args * @throws Exception */ public static void main(String[] args)throws Exception { String url = ""; GetUrlInfor geturlinfor = new GetUrlInfor(url); geturlinfor.printinfor(); } }
上一篇:Visual C++常用数据类型转换详解
下一篇:提取百度搜索结果
登录 注册