📄 weather.java~315~
字号:
package wapserver;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author unascribed * @version 1.0 */import java.util.*;import java.io.*;public class Weather { //54511,北京,北京,116.17,39.56,54.7,100000,010,04:46,19:47, //0624,0625,00404,10000,23021,52222,63078,73051,13000, // 0626,00402,10000,22133, // 0627,00200,10000,22236, // 0628,00101,10000,21931, // 0629,00101,10000,22030 public Weather() { } public String Get_Weather_B_Url(Vector v,int day){ String w = Get_Weather(v,day); System.out.println("b"+w); String result = "无数据"; StringTokenizer st = new StringTokenizer(w,"-"); if(st.hasMoreElements() ){ result = (String)st.nextElement() ; } result = Utility.getWeatherSmallPic(result); return result; } public String Get_Weather_E_Url(Vector v,int day){ String w = Get_Weather(v,day); String result = "无数据"; StringTokenizer st = new StringTokenizer(w,"-"); if(st.hasMoreElements() ){ result = (String)st.nextElement() ; } if(st.hasMoreElements() ){ result = (String)st.nextElement() ; } result = Utility.getWeatherSmallPic(result); return result; } public String Get_Weather(Vector v,int day){ //54511(1),北京,北京,116.17,39.56,54.7,100000,010,04:46,19:47(10), //0624,0625,00404,10000,23021,52222,63078,73051,13000(19), // 0626,00402,10000,22133(23), // 0627,00200,10000,22236(27), // 0628,00101,10000,21931(31), // 0629,00101,10000,22030,08:00(36) String result = "无数据"; try{ if(day == 1){ result = (String)v.get(12); }else if(day == 2){ result = (String)v.get(20); }else if(day == 3){ result = (String)v.get(24); }else if(day == 4){ result = (String)v.get(28); }else if(day == 5){ result = (String)v.get(32); } }catch(Exception e){ } result = decodeWeather(result); return result; } public String Get_Wind(Vector v,int day){ //54511(1),北京,北京,116.17,39.56,54.7,100000,010,04:46,19:47(10), //0624,0625,00404,10000,23021,52222,63078,73051,13000(19), // 0626,00402,10000,22133(23), // 0627,00200,10000,22236(27), // 0628,00101,10000,21931(31), // 0629,00101,10000,22030,08:00(36) String result = "无数据"; try{ if(day == 1){ result = (String)v.get(13); }else if(day == 2){ result = (String)v.get(21); }else if(day == 3){ result = (String)v.get(25); }else if(day == 4){ result = (String)v.get(29); }else if(day == 5){ result = (String)v.get(33); } }catch(Exception e){ } System.out.println("getWind:"+result); result = decodeWind(result); return result; } public String Get_Temp(Vector v,int day){ //54511(1),北京,北京,116.17,39.56,54.7,100000,010,04:46,19:47(10), //0624,0625,00404,10000,23021,52222,63078,73051,13000(19), // 0626,00402,10000,22133(23), // 0627,00200,10000,22236(27), // 0628,00101,10000,21931(31), // 0629,00101,10000,22030,08:00(36) String result = "无数据"; try{ if(day == 1){ result = (String)v.get(14); }else if(day == 2){ result = (String)v.get(22); }else if(day == 3){ result = (String)v.get(26); }else if(day == 4){ result = (String)v.get(30); }else if(day == 5){ result = (String)v.get(34); } }catch(Exception e){ } result = decodeTemp(result); return result; } //================================ public Vector GetAll(String cityName,String path){//今天 通过城市名查找到行,并且将其分解到Vector中 File file = new File("../f.txt"); try{ System.out.println("creatFile: "+file.createNewFile() ); }catch(Exception e){ e.printStackTrace() ; } String str = GetLineByCity(cityName,path); Vector v = new Vector(); v.removeAllElements() ; StringTokenizer st = new StringTokenizer(str,","); System.out.println(st.countTokens()); while(st.hasMoreElements() ){ String str1 = (String)st.nextElement(); System.out.println(str1); v.addElement(str1) ; } return v; } public Vector GetPreAll(String cityName,String path){//昨天 通过城市名查找到行,并且将其分解到Vector中 String str = GetPreLineByCity(cityName,path); Vector v = new Vector(); v.removeAllElements() ; StringTokenizer st = new StringTokenizer(str,","); System.out.println(st.toString() ); while(st.hasMoreElements() ){ v.addElement((String)st.nextElement()) ; } return v; } public String GetLineByCity(String cityName,String path){//获得 当天 的5天预报行 String result = "无数据";//"54511,北京,北京,116.17,39.56,54.7,31,1,晴,32℃-18℃,风力小于3级,强,可吸入颗粒物,良,2,晴,18℃-33℃,风力小于3级,3,晴,19℃-31℃,风力小于3级,05:15,04:49,19:35"; for(int i = 24;i>=0;i--){//找到最新的数据文件,从24小时到着找。 String hh = ""; if(i<10){ hh = "0"+String.valueOf(i); }else{ hh = String.valueOf(i); } File file = new File(path+"forecast"+Utility.getFileDateString()+hh+".txt"); System.out.println(path+"forecast"+Utility.getFileDateString()+hh+".txt"); if(file.exists() && file.length() >0 ){ System.out.println("find file"); try{ BufferedReader br = new BufferedReader((new FileReader(file))); while(!(result = br.readLine() ).equals("") ){ if(result.indexOf(cityName) != -1){ System.out.println(result); br.close() ; return result; } } }catch(Exception e){ e.printStackTrace() ; } } } return result; } public String GetPreLineByCity(String cityName,String path){//获得 昨天 的5天预报行 String result = "无数据";//"54511,北京,北京,116.17,39.56,54.7,31,1,晴,32℃-18℃,风力小于3级,强,可吸入颗粒物,良,2,晴,18℃-33℃,风力小于3级,3,晴,19℃-31℃,风力小于3级,05:15,04:49,19:35"; for(int i = 24;i>=0;i--){ String hh = ""; if(i<10){ hh = "0"+String.valueOf(i); }else{ hh = String.valueOf(i); } File file = new File(path+"forecast"+Utility.getPreFileDateString()+hh+".txt"); System.out.println(path+"forecast"+Utility.getPreFileDateString()+hh+".txt"); if(file.exists() && file.length() >0 ){ System.out.println("find file"); try{ BufferedReader br = new BufferedReader((new FileReader(file))); while(!(result = br.readLine() ).equals("") ){ if(result.indexOf(cityName) != -1){ System.out.println(result); br.close() ; return result; } } }catch(Exception e){ e.printStackTrace() ; } } } return result; } public String Phenomena(String strData){ if (strData.equals("00")) return "晴"; else if (strData.equals("01")) return "多云"; else if (strData.equals("02")) return "阴"; else if (strData.equals("03"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -