acc
wlcacc
全部博文(170)
FireWorkflow(0)
Oracle(9)
ExtJS(19)
面试题集锦(5)
其他(2)
JavaScript(22)
DIV+CSS(12)
网页制作(0)
网络技术(2)
ASP(1)
Tomcat(1)
OS(0)
DB(0)
Hibernate(5)
Java(0)
Spring(1)
Struts(2)
Fireworks(15)
Windows(7)
Java(30)
MySQL(11)
2014年(7)
2010年(2)
2009年(62)
2008年(25)
2007年(67)
2006年(7)
knife800
alunfirs
格伯纳
Bsolar
浪花小雨
chengccy
qingfeng
laishiwa
Iqcw1368
分类: Java
2009-09-17 18:17:42
package test;public class Astro { public static void main(String args[]) { get(); } public static void get(){// String url [][]={// {"Sina_Today",""},// {"Sina_Tomorrow",""},// {"TQ",""},// // };// for(int i=0;i// saveFile("C:\\TEMP\\"+url[i][0]+".html",getHtml(url[i][1])); System.out.println(getTemp()); } public static String getImgPath(){ String html=getHtml(""); String regex="; String path="images/sun.png"; java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex); java.util.regex.Matcher m = pattern.matcher(html); if(m.find())path=m.group(1); return path; } public static String getTemp(){ String html=getHtml(""); String t="20"; String regex="([0-9]+)℃~([0-9]+)℃"; System.out.println(regex); java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex); java.util.regex.Matcher m = pattern.matcher(html); int g=0;int d=0; if(m.find()){ g=Integer.parseInt(m.group(2)); d=Integer.parseInt(m.group(1)); } t=String.valueOf((d+g)/2); return t; } public static String getHtml(String urlString) { try { StringBuffer html = new StringBuffer(); java.net.URL url = new java.net.URL(urlString); java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection(); java.io.InputStreamReader isr = new java.io.InputStreamReader(conn.getInputStream()); java.io.BufferedReader br = new java.io.BufferedReader(isr); String temp; while ((temp = br.readLine()) != null) { html.append(temp).append("\n"); } br.close();isr.close(); return html.toString(); } catch (Exception e) { e.printStackTrace();return null;} }// public static void saveFile(String ff, String s) {// try {// File f = new File(ff);// PrintWriter flow = new PrintWriter(new FileWriter(f));// flow.println(s);// flow.close();// } catch (IOException e) {// e.printStackTrace();// }// }}
上一篇:Java正则表达式详解
下一篇:生气的时候不要作任何决定
登录 注册