- 想了解更多的朋友可参考链接:超链接
- 代码已经取了前两位与FF进行了异或,直接运行即可
import java.io.*;
public class ConvertDat {
public static void main(String[] args) throws Exception {
String srcPath = "F:/";
String outPath = "F:/";
File file = new File(srcPath);
File[] files = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".dat");
}
});
assert files != null;
for (File f : files) {
InputStream in = new FileInputStream(f);
int read = in.read();
int xorResult = read ^ 0xFF;
in = new FileInputStream(f);
OutputStream out = new FileOutputStream(outPath + f.getName()
.replace(".dat", ".png"));
byte[] buffer = new byte[1024];
int r;
byte[] outBuffer = new byte[1024];
while ((r = in.read(buffer)) > 0) {
for (int i = 0; i < r; i++) {
byte b = buffer[i];
int c = b ^ xorResult;
Byte aByte = (byte) c;
outBuffer[i] = aByte;
}
out.write(outBuffer, 0, r);
out.flush();
}
in.close();
out.close();
}
}
}