解析XML文件,生成 String

/** * * @param path * @return * @throws Exception */ public String readXmlForString(String path) throws Exception{ InputStream in = XNetService.class.getResourceAsStream(path); Reader reader = new InputStreamReader(in); BufferedReader bf=new BufferedReader(reader); StringBuffer str=new StringBuffer(); String row=null; while(null!=(row=bf.readLine())){ if(!row.equals("")){ str.append(row).append("\n"); } } String string = str.toString(); return string; } 以上XNetService是一个类名称.String path是文件存放的目录



欢迎关注公众号:Java后端技术全栈