文件加解密

 
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
 * @see 文件加解密 , 简单的将文件的字节编码进行了 +- 操作
 * @author THE GIFTED
 *
 */
public class FileEnc {

	public static void main(String[] args) throws Exception {
		System.out.println(-1 - 10);

		System.out.println(-(-11 + 1));

		String path = "D:\\1tmp\\enc" + File.separator + "scdec.zip";
		String encPath = "D:\\1tmp\\enc" + File.separator + "encsc.zip";

		File rfile = new File(path);
		System.out.println(rfile.isFile());
		System.out.println(rfile.exists());

		File eFile = new File(encPath);

		FileInputStream fis = new FileInputStream(eFile);

		FileOutputStream fos = new FileOutputStream(rfile);

//		BufferedOutputStream bos = new BufferedOutputStream(arg0)

		transFoToFileDec(fis, fos);

	}

	/**
	 * @author THE GIFTED
	 * @see 文件传输解密
	 * @param fis
	 * @param fos
	 */
	public static void transFoToFileDec(FileInputStream fis, FileOutputStream fos) {
		try {
			byte[] b = new byte[1024 * 10];
			int len = 0;

			while ((len = fis.read(b)) != -1) {

				for (int j = 0; j < len; j++) {
					b[j] = (byte) (-((int) b[j] + 1));
				}

				fos.write(b, 0, len);
			}
		} catch (Exception e) {
			System.out.println(e);
			throw new RuntimeException("文件复制失败"); // 手动抛除异常
		} finally {
			if (fos != null) {
				try {
					fos.close();
				} catch (IOException e) {
					e.printStackTrace();
				} finally {
					if (fis != null) {
						try {
							fis.close();
						} catch (IOException e) {
							System.out.println(e);
							throw new RuntimeException("文件复制失败");
						}
					}
				}
			}
		}

	}

	/**
	 * @author THE GIFTED
	 * @see 文件传输加密
	 * @param fis
	 * @param fos
	 */
	public static void transFoToFileEnc(FileInputStream fis, FileOutputStream fos) {
		try {
			byte[] b = new byte[1024 * 10];
			int len = 0;

			while ((len = fis.read(b)) != -1) {

				for (int j = 0; j < len; j++) {
					b[j] = (byte) (-1 - (int) b[j]);
				}

				fos.write(b, 0, len);
			}
		} catch (Exception e) {
			System.out.println(e);
			throw new RuntimeException("文件复制失败"); // 手动抛除异常
		} finally {
			if (fos != null) {
				try {
					fos.close();
				} catch (IOException e) {
					e.printStackTrace();
				} finally {
					if (fis != null) {
						try {
							fis.close();
						} catch (IOException e) {
							System.out.println(e);
							throw new RuntimeException("文件复制失败");
						}
					}
				}
			}
		}

	}
}