import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo_02 {
public static void main(String[] args) {
File file = new File("Koala.jpg");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try{
if(file.exists()){
bis = new BufferedInputStream(new FileInputStream(file));
}else{
System.out.println("文件不存在");
}
//进行加密 加密后 再写出到新文件2.jpg
bos = new BufferedOutputStream(new FileOutputStream("2.jpg"));
int i = 0;
while((i = bis.read())!=-1){
bos.write(i^123^123);
//一个数 异或另一个数两次 结果还是这个数本身
bos.flush();
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
if(bis!=null)
bis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(bos!=null)
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}