码迷,mamicode.com
首页 > 其他好文 > 详细

图片加密解密小知识

时间:2016-05-08 15:02:02      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

代码如下

public static void main(String[] args) {
        //输入流,图片路径(相对路径),加密
        try {
            FileInputStream fis = new FileInputStream("pic/绿茶.jpg");
            FileOutputStream fos = new FileOutputStream("pic/绿茶_last.jpg");//加密后文件名
            int b;
            try {
                while((b = fis.read()) != -1){
                    fos.write(b^1234);
                }
            }
            catch (IOException e) {//捕捉IO 异常
                e.printStackTrace();
            }
        }
        catch (FileNotFoundException e) {//捕捉File找不到异常
            e.printStackTrace();
        }
    }
public static void main(String[] args) {
      //输入流,图片路径(相对路径),解密
        try {
            FileInputStream fis = new FileInputStream("pic/绿茶_last.jpg");
            FileOutputStream fos = new FileOutputStream("pic/绿茶解密.jpg");//加密后文件名
            int b;
            try {
                while((b = fis.read()) != -1){
                    fos.write(b^1234);
                }
            }
            catch (IOException e) {//捕捉IO 异常
                e.printStackTrace();
            }
        }
        catch (FileNotFoundException e) {//捕捉File找不到异常
            e.printStackTrace();
        }
    }

 

初学者如有疑问,留言联系,谢谢……

图片加密解密小知识

标签:

原文地址:http://www.cnblogs.com/wanghui1316/p/5470440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!