代码如下:

 

//将一个字符串转化为输入流
public static InputStream getStringStream(String sInputString){ 
if (sInputString != null && !sInputString.trim().equals("")){ 
try{ 
ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(sInputString.getBytes()); 
return tInputStringStream; 
}catch (Exception ex){ 
ex.printStackTrace(); 
} 
} 
return null; 
}

例如,你在做一个文件流解析的时候,别人返回来给你的就是一个字符串格式的报文xml,你就需要这样做:

/**将服务器返回的交易报文xml转换为交易结果对象
     * 
     * @author : EX-CHENWEIXIAN001 陈惟鲜
     * @create_date :2013-8-2 下午01:40:25
     * @param reponseXml
     * @return
     * @throws IOException 
     * @throws JDOMException 
     * @throws UnsupportedEncodingException 
     */
    public static CmsDealResponseDTO xmlToCmsDealResponseDTO(String reponseXml) throws UnsupportedEncodingException, JDOMException, IOException
    {
        if (reponseXml == null)
        {
            return null;
        }

        CmsDealResponseDTO cmsDealResponseDTO = null;
        SAXBuilder sax = new SAXBuilder();
        
        Document doc = sax.build( new ByteArrayInputStream(reponseXml.getBytes("UTF-8")));
        Element root = doc.getRootElement(); // 根结点
        List<Element> chlidrenList = root.getChildren();
        cmsDealResponseDTO = setCmsDealResponseDTO(chlidrenList);

        return cmsDealResponseDTO;
    }

 




相关文章:

  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2021-09-07
  • 2022-01-13
  • 2021-11-07
猜你喜欢
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-07-21
相关资源
相似解决方案