首先在c盘jingtianxiaozhi目录下放一张图片wang.png如下,然后运行一下代码
try {
FileInputStream fileInputStream=new FileInputStream(new File("c:\\jingtianxiaozhi\\wang.png"));
FileOutputStream fileOutputStream=new FileOutputStream(new File("c:\\jingtianxiaozhi\\wang2.png"));
int b;
while((b=fileInputStream.read())!=-1)
{
fileOutputStream.write(b^6);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
首先在c盘jingtianxiaozhi目录下生成加密之后的图片wang2.png,打开如下。然后再运行解密代码。
try {
FileInputStream fileInputStream=new FileInputStream(new File("c:\\jingtianxiaozhi\\wang2.png"));
FileOutputStream fileOutputStream=new FileOutputStream(new File("c:\\jingtianxiaozhi\\wang3.png"));
int b;
while((b=fileInputStream.read())!=-1)
{
fileOutputStream.write(b^6);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
首先在c盘jingtianxiaozhi目录下生成解密之后的图片wang3.png,跟原图一模一样。