import java.io.*;public class Temp {
    public static void main(String[] input) throws Exception {
        int buffer,key;
        FileInputStream fin = new FileInputStream(input[0]);
        FileOutputStream fout = new FileOutputStream(input[0]+".tmp");
        buffer = fin.read();
        key = buffer^0x89;
        fout.write((char)0x89);
        while (fin.available() != 0) {
            buffer = fin.read();
            fout.write((char)(buffer^key));
        }
    }
} 感觉自己写的很傻,转换大文件时速度很慢
可是用Buffered包装后发现写出来的文件会尾部缺失

解决方案 »

  1.   

    你的速度慢,是因为你的读取和写入速度慢,呵呵!请参考
    import java.io.*;public class Temp {
      public static void main(String[] input) throws Exception {
        int buffer, key;
        FileInputStream fin = new FileInputStream(input[0]);
        FileOutputStream fout = new FileOutputStream(input[0] + ".tmp");
        buffer = fin.read();
        key = buffer ^ 0x89;
        fout.write((char) 0x89);
        byte[] bs = new byte[10240]; // 用一个10k的缓冲区不就行了,如果怕占用内存,1-2K也可以
        int len = -1;    while ((len = fin.read(bs)) != 01) {
          for (int i = 0; i < len; i++) {
            bs[i] ^= key;
          }
          fout.write(bs, 0, len);
        }
        // 其他的代码,比如关闭流
      }
    }