博客
关于我
java实现简单文件加密解密
阅读量:609 次
发布时间:2019-03-12

本文共 694 字,大约阅读时间需要 2 分钟。

/** * 加密解密 * @param filePath 文件路径 * @param code 加密解密码 * @throws IOException * @return 加密后文件生成路径 */public static String enOrDecryption(String filePath,int code) throws IOException {    if(filePath==null||filePath.trim().equals("")){        return "";    }    File oldFile=new File(filePath);    //原文件输入流    FileInputStream fis=new FileInputStream(oldFile);    //加密后文件输出流    File newFile=new File(oldFile.getParent(),"m"+oldFile.getName());    FileOutputStream fos=new FileOutputStream(newFile);    while (true){        int i=fis.read();        if(i==-1) break;        //异或操作:X^A^A=X^(A^A)=X^0=X        fos.write(i^code);    }    fis.close();    fos.close();    return newFile.getAbsolutePath();}

 

转载地址:http://kgtxz.baihongyu.com/

你可能感兴趣的文章
mysql出现错误的解决办法
查看>>
MySQL函数
查看>>
mysql函数汇总之字符串函数
查看>>
mysql函数汇总之数学函数
查看>>
mysql函数汇总之日期和时间函数
查看>>
mysql函数汇总之条件判断函数
查看>>
mysql函数汇总之系统信息函数
查看>>
MySQL函数简介
查看>>
mysql函数遍历json数组
查看>>
MySQL函数(转发)
查看>>
mysql分区表
查看>>
MySQL分层架构与运行机制详解
查看>>
mysql分库分表中间件简书_MySQL分库分表
查看>>
MySQL分库分表会带来哪些问题?分库分表问题
查看>>
MySQL分组函数
查看>>
MySQL分组查询
查看>>
Mysql分表后同结构不同名称表之间复制数据以及Update语句只更新日期加减不更改时间
查看>>
mySql分页Iimit优化
查看>>
MySQL分页查询
查看>>
WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 Selenium 的 Chrome 二进制错误
查看>>