栏目导航
热点推荐
- 三十条有用的 Java 编程规则
- Java制作水印图片源码
- Java常见异常及可能的导致原因
- Java中的修饰词使用方法总结
- J2EE系统异常的处理准则
- Java中的异常、断言、日志解析(
- Java面试技巧:Java面试题集锦(
- 面向Java开发人员的Scala指南:
- Java程序员:一刻钟精通正则表达
- 网友经验分享:学好java开发的关
- 专家解答:创建表格与数据库进行
- Java远程访问Domino数据库
阅览排行
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&id_u=$id_u$" img="local://resources/desktop/2.png"/> <gridItem text="集团产品" url="$server_path$/Api.ashx?function=getProduct&id_u=$id_u$" img="local://resources/desktop/3.png"/> <gridItem text="知识库" url="$server_path$/Api.ashx?function=getKnowledgeTypes&id_u=$id_u$" img="local://resources/desktop/0.png"/> <gridItem text="信息采集" url="$server_path$/Api.ashx?function=getCollType&id_u=$id_u$" img="local://resources/desktop/1.png"/> <gridItem text="在线交流" url="$server_path$/Api.ashx?function=getMyQuestionList&id_u=$id_u$&id_acc=$id_acc$" img="local://resources/desktop/4.png"/> <gridItem text="通讯录" url="$server_path$/Api.ashx?function=getAddrTypes&id_u=$id_u$" img="local://resources/desktop/5.png"/> <gridItem text="广播信息" url="$server_path$/Api.ashx?function=getNewsList&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&id_u=$id_u$" img="local://resources/desktop/2.png"/> <gridItem text="集团产品" url="$server_path$/Api.ashx?function=getProduct&id_u=$id_u$" img="local://resources/desktop/3.png"/> <gridItem text="知识库" url="$server_path$/Api.ashx?function=getKnowledgeTypes&id_u=$id_u$" img="local://resources/desktop/0.png"/> <gridItem text="信息采集" url="$server_path$/Api.ashx?function=getCollType&id_u=$id_u$" img="local://resources/desktop/1.png"/> <gridItem text="在线交流" url="$server_path$/Api.ashx?function=getMyQuestionList&id_u=$id_u$&id_acc=$id_acc$" img="local://resources/desktop/4.png"/> <gridItem text="通讯录" url="$server_path$/Api.ashx?function=getAddrTypes&id_u=$id_u$" img="local://resources/desktop/5.png"/> <gridItem text="广播信息" url="$server_path$/Api.ashx?function=getNewsList&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(); } |
1
上一篇:J2EE系统异常的处理准则 下一篇:Java EE 6 引入的三大新技术之JAX-RS