博客
关于我
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中varchar类型数字排序不对踩坑记录
查看>>
MySQL中一条SQL语句到底是如何执行的呢?
查看>>
MySQL中你必须知道的10件事,1.5万字!
查看>>
MySQL中使用IN()查询到底走不走索引?
查看>>
Mysql中使用存储过程插入decimal和时间数据递增的模拟数据
查看>>
MySql中关于geometry类型的数据_空的时候如何插入处理_需用null_空字符串插入会报错_Cannot get geometry object from dat---MySql工作笔记003
查看>>