举例代码如下:
class Demo
{
public static void main(String args[]) throws Exception
{
System.out.println("请输入密码:");
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int key = Integer.parseInt(br.readLine());
//此处也可以自定义key的值
encrypt(key,"1.txt","2.txt");
}
static void encrypt(int key,String file1,String file2) throws Exception
{
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
int ch = 0 ;
while((ch=fis.read())!=-1)
{
ch = ch^key;
fos.write(ch);
}
fis.close();
fos.close();
}
}
最新评论