package xxx;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 第一次加密,执行第二次解密
* @author hgg
* @version 2016年2月26日下午5:11:40
*/
public class 加密解密 {
public static void main(String[] args) throws IOException {
File file = new File("D:/tmp/test");
InputStream is = new FileInputStream(file);
writeToLocal("D:/tmp/test2",is);
}
/**
* 流写入本地文件
*
* @param destination
* @param input
* @throws IOException
*/
private static void writeToLocal(String destination, InputStream input)
throws IOException {
int index;
byte[] bytes = new byte[1024];
byte[] bytes2 = new byte[1024];
FileOutputStream downloadFile = new FileOutputStream(destination);
while ((index = input.read(bytes)) != -1) {
for (int i = 0; i
//通过异或运算某个数字或字符串(这里以2为例)
bytes2[i] = (byte) (bytes[i]^2);
}
downloadFile.write(bytes2, 0, index);
downloadFile.flush();
}
downloadFile.close();
}
}