<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 閱讀(1458) 評論(0)  編輯  收藏


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


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     
    主站蜘蛛池模板: 亚洲人成网77777亚洲色| 18禁无遮挡无码网站免费| 亚洲国产成人九九综合| 免费高清在线爱做视频| 亚洲a一级免费视频| 蜜桃传媒一区二区亚洲AV| 2022年亚洲午夜一区二区福利| 国产自产拍精品视频免费看| 久久aⅴ免费观看| av午夜福利一片免费看久久| 亚洲中文无码亚洲人成影院| 久久亚洲私人国产精品vA| 狠狠亚洲婷婷综合色香五月排名| 亚洲免费综合色在线视频| 成人免费观看一区二区| 日本视频在线观看永久免费| 99免费精品视频| 91免费福利视频| 四虎影视在线影院在线观看免费视频 | 成年18网站免费视频网站| 99久久久国产精品免费牛牛| A国产一区二区免费入口| 皇色在线免费视频| 水蜜桃视频在线观看免费| 国产美女精品久久久久久久免费| 久久综合给合久久国产免费| 久久A级毛片免费观看| 99国产精品永久免费视频| 一二三四在线观看免费高清中文在线观看 | 色费女人18女人毛片免费视频| 午夜成人无码福利免费视频| 51午夜精品免费视频| 中文字幕免费视频| 午夜视频免费观看| 亚洲中文字幕无码一久久区| 亚洲AV无码成人精品区在线观看 | 久久久久久国产a免费观看黄色大片 | 成人影片麻豆国产影片免费观看 | 久久久久久毛片免费播放| 久久不见久久见免费影院| 国产专区一va亚洲v天堂|