二级java:获取网站的实时股票数据
来源:优易学  2011-9-18 15:32:40   【优易学:中国教育考试门户网】   资料下载   IT书店

 

 91. }catch(Exception e){return "出现错误!\n也许是网络连接错误、股票根本不存在或者现在股票休市!";}//出错则返回空字符
  92.
  93. }
  94.
  95.
  96.
  97.
  98.
  99. public String XMLToString(byte[] rec,String[] strs_filter) { //从字节读取内容
  100.
  101. ByteArrayInputStream bais = new ByteArrayInputStream(rec);
  102.
  103. DataInputStream dis = new DataInputStream(bais);
  104.
  105. String BTS=null;
  106.
  107. try {
  108.
  109. BTS=new String(rec,"UTF-8");
  110.
  111. bais.close();
  112.
  113. dis.close();
  114.
  115. } catch (Exception e) {
  116.
  117. e.printStackTrace();
  118.
  119. }
  120.
  121. if (BTS.indexOf("")>0)//表示不能转换为汉字,则要过滤转换(提高效率)
  122.
  123. {
  124.
  125. for(int i=0;i<strs_filter.length;i++)//根据字段,循环把汉字替换为UTF码
  126.
  127. {
  128.
  129. BTS=replaceStr(BTS,GBtoUTF(strs_filter[i]),strs_filter[i]);
  130.
  131. }
  132.
  133. }
  134.
  135. return BTS;
  136.
  137. }
  138.
  139.
  140.
  141. //从一堆XML代码中搜索有用的股票信息
  142.
  143. //根据strs_filter的元素作为查找字符串的开头
  144.
  145. //end作为结尾
  146.
  147. //separator作为分隔头和尾的标志
  148.
  149. public String ReturnStock(String content,String separator,String end,String[] strs_filter)
  150.
  151. {
  152.
  153. String str="",str_fieldname="";
  154.
  155. for(int i=0;i<strs_filter.length;i++)
  156.
  157. {
  158.
  159. int pos1=content.indexOf(strs_filter[i]);
  160.
  161. int pos2=content.indexOf(separator, pos1+1);
  162.
  163. int pos3=content.indexOf(end, pos2+1);
  164.
  165. str_fieldname=content.substring(pos1, pos1+strs_filter[i].length());
  166.
  167. str=str+"\n"+str_fieldname+content.substring(pos2, pos3);
  168.
  169. }
  170.
  171. return str;
  172.
  173. }
  174.
  175. //----------------------一下两个函数GBtoUTF,replaceStr配合一起使用---------------------------------
  176.
  177. //把汉字转化为UTF代码
  178.
  179. public static String GBtoUTF(String gb2312String) {
  180.
  181. if (gb2312String == null) {
  182.
  183. return null;
  184.
  185. }

上一页  [1] [2] [3] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训