Java : Convert formatted xml file to one line string

前端 未结 10 1436
时光取名叫无心
时光取名叫无心 2020-12-01 04:02

I have a formatted XML file, and I want to convert it to one line string, how can I do that.

Sample xml:



        
10条回答
  •  猫巷女王i
    2020-12-01 04:28

    //filename is filepath string
    BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
    String line;
    StringBuilder sb = new StringBuilder();
    
    while((line=br.readLine())!= null){
        sb.append(line.trim());
    }
    

    using StringBuilder is more efficient then concat http://kaioa.com/node/59

提交回复
热议问题