public static String transferUTF8(String xml, String fileNamePath) throws Exception{ String str = null; TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tFactory.newTransformer(new StreamSource(XMLTransTool.class.getClassLoader().getResourceAsStream(fileNamePath))); StreamSource streamSource = new StreamSource(new ByteArrayInputStream(xml.replaceFirst("GBK", "UTF-8").getBytes("UTF-8"))); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); transformer.transform(streamSource, new StreamResult(byteStream)); str = new String(byteStream.toByteArray(),"UTF-8"); } catch (TransformerConfigurationException e) { throw e; } catch (TransformerException e) { if(e.getMessage().contains("UnsupportDateException")){ throw new UnsupportDateException(e.getMessage()); }else{ throw new Exception(e); } } catch (UnsupportedEncodingException e) { throw e; } return str; }
结合xsl转换报文
猜你喜欢
转载自lysunki.iteye.com/blog/2203259
今日推荐
周排行