public class TestSteam {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//加密
encryptionFile();
//解密
decodeFile();
}
public static void encryptionFile() throws IOException {
File file = new File("E:\\123456.txt");
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("F:\\123456加密.txt"));
int i = -1;
String str = null;
int i2 = 0;
int i3 = 1;
while((i = in.read()) != -1) {
System.out.println("i等于"+ i);
if(i > 100) {
i = i - 1;
} else if(i < 100) {
i = i+1;
}
out.write(i);
}
in.close();
out.close();
System.out.println("加密成功");
}
public static void decodeFile() throws IOException {
File file = new File("F:\\123456加密.txt");
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("F:\\123456解密.txt"));
int i = -1;
while((i = in.read()) != -1) {
System.out.println("i等于"+ i);
if(i > 100) {
i = i + 1;
}else if(i<=100) {
i = i-1;
}
out.write(i);
}
in.close();
out.close();
System.out.println("解密成功");
}
}