氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          java之base64code

          最近在做項目中遇到base64code處理的問題。下面是我寫的示例: 
          原文參考自站長網
          http://www.software8.co/wzjs/java/2610.html
          Java代碼 :
          1. package com.juck.test;  
          2. import java.io.File;  
          3. import java.io.FileInputStream;  
          4. import java.io.FileOutputStream;  
          5. import java.io.IOException;  
          6. import sun.misc.BASE64Decoder;  
          7. import sun.misc.BASE64Encoder;  
          8. public class Base64Code{   
          9.     //測試主方法  
          10.     public static void main(String[] args){  
          11.       
          12.         final String fileName = "示例文件";  
          13.         final String fileSuffix = ".jpg";  
          14.         final String url = "XXXXXXX";//文件路徑  
          15.         try{  
          16.             String base64Code=encoderToBase64Code(url);  
          17.             base64CodeToFile(base64Code,"D:\\BASE64編碼字符串"+fileName+".txt");  
          18.             decoderToBase64Code(base64Code,"D:\\解碼"+fileName+fileSuffix);  
          19.         }catch(Exception e){  
          20.             e.printStackTrace();  
          21.         }  
          22.    }  
          23.     //文件轉換程BASE64編碼  
          24.     public static String encoderToBase64Code(String path)throws IOException{  
          25.       
          26.           File file = new File(path);  
          27.           FileInputStream input = new FileInputStream(file);  
          28.           byte[] buffer = new byte[(int)file.length()];  
          29.           input.read(buffer);  
          30.           input.close();  
          31.           System.out.print(new BASE64Encoder().encode(buffer));//打印文件經過編碼后的字符串  
          32.           return new BASE64Encoder().encode(buffer);  
          33.     }    
          34.     //BASE64字符串解碼并保存文件  
          35.     public static void decoderToBase64Code(String base64Code,String targetPath) throws IOException{  
          36.           byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);  
          37.           FileOutputStream out = new FileOutputStream(targetPath);  
          38.           out.write(buffer);  
          39.           out.close();  
          40.      //BASE64字符串保存成文本  
          41.      public static void base64CodeToFile(String base64Code,String targetPath) throws IOException{  
          42.            byte[] buffer = base64Code.getBytes();  
          43.            FileOutputStream out = new FileOutputStream(targetPath);  
          44.            out.write(buffer);  
          45.            out.close();  
          46.      }   
          47.     }  
          48. }  

          posted on 2013-01-14 09:03 你爸是李剛 閱讀(372) 評論(0)  編輯  收藏


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 常熟市| 布尔津县| 罗江县| 永宁县| 万荣县| 神木县| 东明县| 永清县| 孝昌县| 昭平县| 新和县| 和田市| 武安市| 都兰县| 锡林浩特市| 巴青县| 裕民县| 阿坝| 酒泉市| 游戏| 盖州市| 伊宁市| 重庆市| 咸丰县| 灯塔市| 阳江市| 庐江县| 泊头市| 蒲城县| 明光市| 伊通| 蛟河市| 息烽县| 凤台县| 习水县| 和田县| 邮箱| 武安市| 土默特右旗| 皋兰县| 皮山县|