package com.company;
import com.itextpdf.text.pdf.PdfReader;
import java.io.*;


public class Main {
public static void main(String[] args) {
Thread t5 =new Thread(){
public void run(){
while(true){
try{
sleep(1000);
new File("请放进来").mkdirs();
File[] files = new File("请放进来").listFiles();
if(files!=null&&files.length>0){
for(File file1:files){
if(file1.getName().toLowerCase().indexOf(".pdf")!=-1){
System.out.println(file1.getName());
String parent = file1.getParent();
if(!isTrue(file1)){
reName(file1,new File(parent+"/错误/"+file1.getName()));
}else{
reName(file1,new File(parent+"/正确/"+file1.getName()));
}
}
}
}

}catch(Exception e){
e.printStackTrace();
}
}
}
};
t5.start();
}

private static void reName(File before, File after) {
String parent = after.getParent();
if(!new File(parent).exists()){
new File(parent).mkdirs();
}
before.renameTo(after);
}

public static boolean isTrue(File file){
try{
PdfReader reader = new PdfReader(file.toString());
byte[] metadata = reader.getMetadata();
String s = new String(metadata);
String CreateDate = s.substring(s.indexOf("<xmp:CreateDate>")+"<xmp:CreateDate>".length(),s.indexOf("</xmp:CreateDate>"));
String ModifyDate = s.substring(s.indexOf("<xmp:ModifyDate>")+"<xmp:ModifyDate>".length(),s.indexOf("</xmp:ModifyDate>"));
reader.close();
return CreateDate.substring(0,"2021-04-14T16:23".length()).equals(ModifyDate.substring(0,"2021-04-14T16:23".length()));
}catch (Exception e){
e.printStackTrace();
}
return false;

}
}