import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class FileTools { public static byte[] key = { 1, 3, 5, 11, 13, 17, 19, 23, 29, 37, 41, 43, 47, 51, 53, 57 }; /** * @param args */ public static void main(String[] args) { if (args.length < 1) { System.out.println(args[0]); System.out.println("Please input file path!"); System.exit(1); } File file = new File(args[0]); if (!file.exists()) { System.out.println(args[0] + " dose not found!"); System.exit(1); } FileInputStream fis = null; try { fis = new FileInputStream(file); } catch (FileNotFoundException e1) { System.out.println(args[0] + " dose not found!"); System.exit(1); } File output = new File(args[0] + ".bk"); try { if (!output.createNewFile()) { System.out.println("Cannot create new file!"); System.exit(1); } } catch (IOException e) { System.out.println("cannot create new file"); System.exit(1); } FileOutputStream fos = null; try { fos = new FileOutputStream(output); } catch (FileNotFoundException e1) { System.out.println("cannot create new file"); System.exit(1); } byte[] temp = new byte[4096]; try { int read_len = 0; while ((read_len = fis.read(temp)) > 0) { for (int i = 0,j = 0; i < read_len; i++) { temp[i] = (byte) (temp[i] ^ key[j++]); if (j == key.length) j = 0; } fos.write(temp, 0, read_len); } } catch (IOException e) { System.out.println("Read/Write found error!"); } finally { if (fos != null) try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }