java.io读取文件疑惑解析
来源:优易学  2011-12-21 16:45:50   【优易学:中国教育考试门户网】   资料下载   IT书店

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

  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();

  }

[1] [2] 下一页

责任编辑:小草

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