java解析带bom头utf-8文件处理

http://blog.csdn.net/mingjian_zheng/archive/2009/05/12/4170519.aspx

去掉bom头方法:

String xmla = StringFileToolkit.file2String(new File("D:\\projects\\mailpost\\src\\a.xml"),"UTF-8"); 
  byte[] b = xmla.getBytes("UTF-8"); 
  String xml = new String(b,3,b.length-3,"UTF-8"); 
  Document doc1 = DocumentHelper.parseText(xml); 
  Element e1 = (Element)doc1.selectSingleNode("/ResponseData/Body/RetDesc"); 
  Element e2 = (Element)doc1.selectSingleNode("/ResponseData/Head/RespID"); 
  Element e3 = (Element)doc1.selectSingleNode("/ResponseData/Body/RetCode"); 
  Element e4 = (Element)doc1.selectSingleNode("/ResponseData/Body/RetDesc");

http://www.java3z.com/cwbwebhome/article/article8/81306.html?id=3094


异常信息:content is not allowed in prolog

dom4j生成xml文件无乱码:http://blog.csdn.net/fightplane/archive/2006/09/06/1185960.aspx

dom4j解析xml文件无乱码方法:
Reader reader = new InputStreamReader(new FileInputStream(inputXml),"utf-8");
SAXReader sax = new SAXReader();
document = sax.read(reader);
 

你可能感兴趣的:(java,html,.net,xml,Blog)