Java by API/java.util.zip/CRC32 — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
CRC32: update(byte[] b, int off, int len)
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.zip.CRC32;
public class Main {
public static void main(String[] args) throws Exception{
BufferedInputStream is = new BufferedInputStream(new FileInputStream("a.exe"));
byte[] bytes = new byte[1024];
int len = 0;
while ((len = is.read(bytes)) >= 0) {
new CRC32().update(bytes, 0, len);
}
is.close();
System.out.println(Arrays.toString(bytes));
}
}
new CRC32()
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
public class Main {
public static void main(String[] args) throws IOException {
FileInputStream fin = new FileInputStream(args[0]);
System.out.println(args[0] + ":\t" + getCRC32(fin));
fin.close();
}
public static long getCRC32(InputStream in) throws IOException {
Checksum cs = new CRC32();
for (int b = in.read(); b != -1; b = in.read()) {
cs.update(b);
}
return cs.getValue();
}
}