chenjinlong

          2011年8月26日 #

          文件加密解密

          /**加密
            *
            */
           public static String doEncrypt(String xmlStr) {
            try {
             return URLEncoder.encode(xmlStr, "GBK");
            } catch (UnsupportedEncodingException e) {
             e.printStackTrace();
            }
            return "加密錯誤";
           }

           /**
            * 解密
            * @param saveFile
            */
           public static void decrypt(File saveFile) {
            try {
             BufferedReader reader = null;
                   reader = new BufferedReader(new FileReader(saveFile));
                   String tempString = null;
                   String str2 =null;
                   while ((tempString = reader.readLine()) != null) {
                    str2=URLDecoder.decode(tempString);
                   }
             FileOutputStream fos = new FileOutputStream(saveFile);
             fos.write(str2.getBytes());
             fos.close();
                   reader.close();
           
            } catch (IOException e) {
             e.printStackTrace();
            }
           }
           
           
           public static void main(String[] args) throws UnsupportedEncodingException {
            
            System.out.println(URLDecoder.decode("C:\\Documents and Settings\\chenchangqing\\Desktop\\實物轉移_20110824030821.xml", "GBK"));
           }




          這是把文件內容轉換成字符的方式

          posted @ 2011-08-26 11:49 chenjinlong 閱讀(191) | 評論 (0)編輯 收藏

          My Links

          Blog Stats

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 庆元县| 开封市| 阿巴嘎旗| 莱州市| 台北市| 吉水县| 固原市| 长治市| 九江县| 长垣县| 武宣县| 府谷县| 环江| 青龙| 尚义县| 三门县| 涞源县| 昌江| 旬阳县| 平远县| 金华市| 阿拉善右旗| 南部县| 遵义县| 淳化县| 长兴县| 吴忠市| 灵宝市| 静安区| 武宣县| 凉山| 京山县| 集安市| 西华县| 禄劝| 通辽市| 湖口县| 丹寨县| 定结县| 泰来县| 林州市|