public class Demo_jiami {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
System.out.println("请输入要加密或解密的文件的绝对路径");
String filename = input.nextLine();
File oldfile = new File(filename);
File newfile = new File(oldfile.getParentFile(),"mi-"+oldfile.getName());
FileInputStream fis = new FileInputStream(oldfile);
FileOutputStream fos = new FileOutputStream(newfile);
while(true){
int b = fis.read();
if(b==-1){
break;
}
//数据^(异或)两次即还原
fos.write(b^10);
}
System.out.println("加密或解密已完成");
}
}


本文介绍了一个Java程序,演示了如何使用Scanner读取用户输入的文件路径,然后通过异或操作对文件进行加密和解密。通过`FileInputStream`和`FileOutputStream`实现文件流操作,适用于基础的文件加密实践。
766

被折叠的 条评论
为什么被折叠?



