54 lines
1.2 KiB
Java
54 lines
1.2 KiB
Java
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
|
|
/**
|
|
* Detects Zip files
|
|
*
|
|
* @author Elia Ali Elmas
|
|
*/
|
|
public class DetectZip {
|
|
|
|
static final String ERR = "error";
|
|
|
|
/**
|
|
* Detects if a given file is a zip-file
|
|
*
|
|
* @param args Filepath
|
|
*/
|
|
public static void main(String[] args) {
|
|
if (args.length != 1) {
|
|
System.out.println(ERR);
|
|
return;
|
|
}
|
|
FileInputStream fin = null;
|
|
try {
|
|
fin = new FileInputStream(new File(args[0]));
|
|
|
|
} catch (Exception e) {
|
|
System.out.println(ERR);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
|
|
byte[] bytes = new byte[2];
|
|
fin.read(bytes);
|
|
fin.close();
|
|
String[] arr = new String[2];
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
arr[i] = Integer.toHexString(bytes[i]);
|
|
}
|
|
if (arr[0].equalsIgnoreCase("50") && arr[1].equalsIgnoreCase("4B")) {
|
|
System.out.println("zip");
|
|
} else {
|
|
System.out.println("no zip");
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
System.out.println(ERR);
|
|
return;
|
|
}
|
|
}
|
|
}
|