posts - 156,  comments - 601,  trackbacks - 0
          公告
          <2008年11月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          常用鏈接

          留言簿(45)

          隨筆分類(145)

          隨筆檔案(110)

          文章檔案(1)

          友情鏈接

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 679816
          • 排名 - 68

          最新評論

          閱讀排行榜

          評論排行榜


          Java Base64 這是一個用于編碼和解碼(encode/decode )base64字符串和數(shù)據(jù)流的Java開源類庫。Base64是網(wǎng)絡上最常見的用于傳輸8Bit字節(jié)代碼的編碼方式之一??捎脕碜鳛殡娮余]件或WebService附件的傳輸編碼.


          使用方法:
            把類庫 javabase64-1.2.jar 設置到編譯路徑中。
           
          示例代碼:
              String類型 進行Base64編碼
              String encoded = Base64.encode("Hello, world!");
             
              String類型 進行Base64解碼
              String decoded = Base64.decode(encoded);
             
              指定字符編碼方式
              String encoded = Base64.encode("Hello, world!", "UTF-8");   
              String decoded = Base64.decode(encoded, "UTF-8");   

          對文件進行編碼:
          如果文件比較小,可以通過以下方式,直接讀取到內(nèi)存中進行編碼處理

          byte[] source = ...; // load your data here
          byte[] encoded = Base64.encode(source);
          byte[] decoded = Base64.decode(encoded);

          如果大件比較大,則建議使用stream:
          代碼示例Base64編碼:
          InputStream inputStream = new FileInputStream("source.jpg");
          OutputStream outputStream = new FileOutputStream("encoded.b64");
          Base64.encode(inputStream, outputStream);
          outputStream.close();
          inputStream.close();

          代碼示例Base64解碼:

          InputStream inputStream = new FileInputStream("encoded.b64");
          OutputStream outputStream = new FileOutputStream("decoded.jpg");
          Base64.decode(inputStream, outputStream);
          outputStream.close();
          inputStream.close();


          Java Base64 項目網(wǎng)址: http://www.sauronsoftware.it/projects/javabase64/

          Good Luck!
          Yours Matthew!

          posted on 2008-11-25 20:23 x.matthew 閱讀(10295) 評論(0)  編輯  收藏 所屬分類: Best Practise(JDK API)
          主站蜘蛛池模板: 宜兴市| 游戏| 佛坪县| 新沂市| 托克逊县| 喜德县| 嫩江县| 嘉鱼县| 黔江区| 定襄县| 庆元县| 天长市| 沂南县| 德庆县| 县级市| 庆阳市| 前郭尔| 泸定县| 崇阳县| 齐齐哈尔市| 永新县| 江陵县| 龙口市| 天长市| 固原市| 岐山县| 延津县| 开原市| 桃源县| 高阳县| 南宁市| 新民市| 正蓝旗| 彩票| 南漳县| 开远市| 读书| 左权县| 兴化市| 如皋市| 蒙城县|