氟塑料離心泵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 你爸是李剛 閱讀(374) 評論(0)  編輯  收藏


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


          網站導航:
           
          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 石林| 邵阳县| 绥德县| 临夏市| 罗平县| 永和县| 叙永县| 永州市| 甘德县| 融水| 孟津县| 会泽县| 亳州市| 武功县| 万全县| 杭锦旗| 淮安市| 绩溪县| 罗源县| 长泰县| 宿迁市| 铜鼓县| 榕江县| 肃南| 张家川| 盐山县| 临漳县| 新宾| 宕昌县| 株洲县| 佛教| 全州县| 辽阳市| 华池县| 镇宁| 汉寿县| 云龙县| 黄浦区| 永胜县| 中西区| 清新县|