• 将一个字符串转换为输入流


    代码如下:

    //将一个字符串转化为输入流
    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;
        }




  • 相关阅读:
    深入Activity生命周期(一)
    android APK 中英文对比(转)
    android中获得系统语言
    mime Contenttype(http head)(转)
    activity设置全屏
    Activity常用知识
    关于这次数学建模
    排列组合
    hdu 1003 笔记
    杂想
  • 原文地址:https://www.cnblogs.com/a393060727/p/3232877.html
Copyright © 2020-2023  润新知