chenjinlong

文件加密解密

/**加密
  *
  */
 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 on 2011-08-26 11:49 chenjinlong 阅读(175) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

Blog Stats

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜