您现在的位置:您现在的位置: 一起学 >> 计算机 >> Java考试认证 >> 综合辅导 >> 公共基础知识指导 >> 正文

java.io读取文件疑惑解析

来源:网友上传  2012-4-25 22:48:54   【一起学:终身教育引导者

  下面是需要用流去读的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] 下一页

来源:网友上传- 公共基础知识指导

责编:上传用户260192  收藏此页 打印 回到顶部