<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    athrunwang

    紀元
    數據加載中……
    InputStream與String,Byte之間互轉
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;

    /**
     *
     * @author Andy.Chen
     * @mail Chenjunjun.ZJ@gmail.com
     *
     */
    public class InputStreamUtils {
        
        final static int BUFFER_SIZE = 4096;
        
        /**
         * 將InputStream轉換成String
         * @param in InputStream
         * @return String
         * @throws Exception
         *
         */
        public static String InputStreamTOString(InputStream in) throws Exception{
            
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] data = new byte[BUFFER_SIZE];
            int count = -1;
            while((count = in.read(data,0,BUFFER_SIZE)) != -1)
                outStream.write(data, 0, count);
            
            data = null;
            return new String(outStream.toByteArray(),"ISO-8859-1");
        }
        
        /**
         * 將InputStream轉換成某種字符編碼的String
         * @param in
         * @param encoding
         * @return
         * @throws Exception
         */
             public static String InputStreamTOString(InputStream in,String encoding) throws Exception{
            
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] data = new byte[BUFFER_SIZE];
            int count = -1;
            while((count = in.read(data,0,BUFFER_SIZE)) != -1)
                outStream.write(data, 0, count);
            
            data = null;
            return new String(outStream.toByteArray(),"ISO-8859-1");
        }
        
        /**
         * 將String轉換成InputStream
         * @param in
         * @return
         * @throws Exception
         */
        public static InputStream StringTOInputStream(String in) throws Exception{
            
            ByteArrayInputStream is = new ByteArrayInputStream(in.getBytes("ISO-8859-1"));
            return is;
        }
        
        /**
         * 將InputStream轉換成byte數組
         * @param in InputStream
         * @return byte[]
         * @throws IOException
         */
        public static byte[] InputStreamTOByte(InputStream in) throws IOException{
            
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] data = new byte[BUFFER_SIZE];
            int count = -1;
            while((count = in.read(data,0,BUFFER_SIZE)) != -1)
                outStream.write(data, 0, count);
            
            data = null;
            return outStream.toByteArray();
        }
        
        /**
         * 將byte數組轉換成InputStream
         * @param in
         * @return
         * @throws Exception
         */
        public static InputStream byteTOInputStream(byte[] in) throws Exception{
            
            ByteArrayInputStream is = new ByteArrayInputStream(in);
            return is;
        }
        
        /**
         * 將byte數組轉換成String
         * @param in
         * @return
         * @throws Exception
         */
        public static String byteTOString(byte[] in) throws Exception{
            
            InputStream is = byteTOInputStream(in);
            return InputStreamTOString(is);
        }

    }

    posted on 2012-01-09 20:02 AthrunWang 閱讀(1453) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲精品456在线播放| 亚洲成色www久久网站夜月| 亚洲日本国产精华液| 国产va在线观看免费| 亚洲AV无码久久精品成人| a毛片视频免费观看影院| 亚洲精品无码国产| 免费观看91视频| 久久久亚洲欧洲日产国码二区| 少妇无码一区二区三区免费| 亚洲黄色免费电影| A在线观看免费网站大全| 亚洲av乱码一区二区三区按摩| 日韩毛片免费在线观看| 边摸边吃奶边做爽免费视频99| xvideos亚洲永久网址| 一区二区三区免费精品视频| 亚洲中文字幕无码一区二区三区| 韩国免费A级毛片久久| 无码乱人伦一区二区亚洲一| 182tv免费观看在线视频 | 亚洲午夜久久久久久噜噜噜| 十八禁视频在线观看免费无码无遮挡骂过| 亚洲精品夜夜夜妓女网| 最近中文字幕完整版免费高清| 2017亚洲男人天堂一| 亚洲成a人片在线观看日本麻豆 | 性xxxx视频播放免费| 美女被爆羞羞网站在免费观看 | 麻豆亚洲AV永久无码精品久久| 黄网站色在线视频免费观看| 亚洲丰满熟女一区二区哦| 亚洲国产成人久久笫一页| 三上悠亚在线观看免费| 亚洲国产精品午夜电影| 国产精品99久久免费| 免费播放在线日本感人片| 亚洲熟妇久久精品| 国产偷v国产偷v亚洲高清| 色se01短视频永久免费| 男人免费视频一区二区在线观看|