java简单加密小程序
来源:互联网 发布:网络通信协议是如何被 编辑:程序博客网 时间:2024/05/21 19:34
public static void main(String[] args) throws IOException { //路径和秘钥 jiamiFile("F:/workspace/Calendar/bbb.txt",12356);}private static void jiamiFile(String url, int key) throws FileNotFoundException, IOException { File file = new File(url); if(!file.exists()){ System.out.println("路径错误"); return; } String path = file.getPath(); //F:\workspace\Calendar\aaa.txt int index = path.lastIndexOf('\\'); //20 String sub = path.substring(0, index+1); //F:\workspace\Calendar\ //System.out.println(sub); String name = file.getName(); //aaa.txt //System.out.println("path= "+path); //System.out.println(sub+"#"+name); FileInputStream fis = new FileInputStream(path); FileOutputStream fos = new FileOutputStream(sub+"#"+name); //F:\workspace\Calendar\#aaa.txt int b; while((b=fis.read())!=-1){ fos.write(b^key); } fis.close(); fos.close(); }
阅读全文