首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>java教程>资讯:java.io需要用流去读的xml文件方法

java.io需要用流去读的xml文件方法

www.jz123.cn  2009-12-19   来源:   中国建站    责任编辑(袁袁)    我要投递新闻

下面是需要用流去读的xml文件:


 <?xml version="1.0" encoding="UTF-8"?> 
  <page pageId ="deskTop" pageTitle="我的桌面" pageVersion="1.0" cache="Check">
  <body bgImage="$bgImage$">
  <gridTable nameId="gid1" location="" size="" rows="3" cols="3">
  <gridItem text="移动产品" url="$server_path$/Api.ashx?function=getGrpProduct&amp;id_u=$id_u$" img="local://resources/desktop/2.png"/>
  <gridItem text="集团产品" url="$server_path$/Api.ashx?function=getProduct&amp;id_u=$id_u$" img="local://resources/desktop/3.png"/>
  <gridItem text="知识库" url="$server_path$/Api.ashx?function=getKnowledgeTypes&amp;id_u=$id_u$" img="local://resources/desktop/0.png"/>
  <gridItem text="信息采集" url="$server_path$/Api.ashx?function=getCollType&amp;id_u=$id_u$" img="local://resources/desktop/1.png"/>
  <gridItem text="在线交流" url="$server_path$/Api.ashx?function=getMyQuestionList&amp;id_u=$id_u$&amp;id_acc=$id_acc$" img="local://resources/desktop/4.png"/>
  <gridItem text="通讯录" url="$server_path$/Api.ashx?function=getAddrTypes&amp;id_u=$id_u$" img="local://resources/desktop/5.png"/>
  <gridItem text="广播信息" url="$server_path$/Api.ashx?function=getNewsList&amp;id_u=$id_u$" img="local://resources/desktop/6.png"/>
  <gridItem text="辅助软件" url="$server_path$/Api.ashx?function=getHelpTool" img="local://resources/desktop/7.png"/>
  <gridItem text="退出系统" url="cmd://exit_app" img="local://resources/desktop/8.png"/>
  </gridTable>
  </body>
  </page>
  <?xml version="1.0" encoding="UTF-8"?>
  <page pageId ="deskTop" pageTitle="我的桌面" pageVersion="1.0" cache="Check">
  <body bgImage="$bgImage$">
  <gridTable nameId="gid1" location="" size="" rows="3" cols="3">
  <gridItem text="移动产品" url="$server_path$/Api.ashx?function=getGrpProduct&amp;id_u=$id_u$" img="local://resources/desktop/2.png"/>
  <gridItem text="集团产品" url="$server_path$/Api.ashx?function=getProduct&amp;id_u=$id_u$" img="local://resources/desktop/3.png"/>
  <gridItem text="知识库" url="$server_path$/Api.ashx?function=getKnowledgeTypes&amp;id_u=$id_u$" img="local://resources/desktop/0.png"/>
  <gridItem text="信息采集" url="$server_path$/Api.ashx?function=getCollType&amp;id_u=$id_u$" img="local://resources/desktop/1.png"/>
  <gridItem text="在线交流" url="$server_path$/Api.ashx?function=getMyQuestionList&amp;id_u=$id_u$&amp;id_acc=$id_acc$" img="local://resources/desktop/4.png"/>
  <gridItem text="通讯录" url="$server_path$/Api.ashx?function=getAddrTypes&amp;id_u=$id_u$" img="local://resources/desktop/5.png"/>
  <gridItem text="广播信息" url="$server_path$/Api.ashx?function=getNewsList&amp;id_u=$id_u$" img="local://resources/desktop/6.png"/>
  <gridItem text="辅助软件" url="$server_path$/Api.ashx?function=getHelpTool" img="local://resources/desktop/7.png"/>
  <gridItem text="退出系统" url="cmd://exit_app" img="local://resources/desktop/8.png"/>
  </gridTable>
  </body>
  </page>

  首先我是用fileInputStream去读的,代码如下:

  Java代码

 


 public static String readXml(String path){
  StringBuffer sb = new StringBuffer();
  try {
  InputStream is = new FileInputStream(path);
  byte[] buffer = new byte[1024];
  while(true){
  int length = is.read(buffer,0,1024);
  if(length == -1) break;
  length = is.read(buffer,0,1024);
  sb.append(new String(buffer));
  }
  } catch (Exception e) {
  e.printStackTrace();
  }
  return sb.toString().trim();
  }
  public static String readXml(String path){
  StringBuffer sb = new StringBuffer();
  try {
  InputStream is = new FileInputStream(path);
  byte[] buffer = new byte[1024];
  while(true){
  int length = is.read(buffer,0,1024);
  if(length == -1) break;
  length = is.read(buffer,0,1024);
  sb.append(new String(buffer));
  }
  } catch (Exception e) {
  e.printStackTrace();
  }
  return sb.toString().trim();
  }

上一篇:J2EE系统异常的处理准则 下一篇:Java EE 6 引入的三大新技术之JAX-RS

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图