----------- android培训、java培训、java学习型技术博客、期待与您交流! ------------
/*
需求:对图片加密。
分析:用异或来异或图片文件再保存。原理就是一个数异或一个数两次还是本数。
*/
import java.io.*;
class JiaMi
{
public static void main(String[] args)
{
jiaMi();
}
public static void jiaMi()
{
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
File file = new File("D:\\day01\\a.jpg");
File file1 = new File("D:\\b.jpg");
try
{
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(new FileOutputStream(file1));
int num = 0;
while ((num = bis.read()) != -1)
{
bos.write(num ^ 0xff);
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
finally
{
try
{
if(bis != null)
bis.close();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
try
{
if(bos != null)
bos.close();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
}
----------- android培训 、 java培训 、java学习型技术博客、期待与您交流! ------------