Java 如果pdf文件不包含文本,如何删除该文件?
我想删除所有不包含文本的pdf文件。我试着用PdfBox。 方法Java 如果pdf文件不包含文本,如何删除该文件?,java,erase,Java,Erase,我想删除所有不包含文本的pdf文件。我试着用PdfBox。 方法pdftoText将pdf转换为字符串 public static void main(String[] args) throws FileNotFoundException, InterruptedException { String pdfText = PDFTextParser.pdftoText("xxx.pdf");
pdftoText
将pdf转换为字符串
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
String pdfText = PDFTextParser.pdftoText("xxx.pdf"); //files[i]);
if (pdfText == "") {
File toBeDeletedFile = new File(location+"xxx.pdf");
if (toBeDeletedFile.delete()) {
System.out.println("success");
}
else {
System.out.println("still there");
}
}
}
}
这并没有带来任何结果
字符串
对象无法在Java中使用=
进行比较
请使用String.equals()
方法
String s1 = "dat1";
String s2 = "dat2";
if(s1.equals(s2))
//dostuff
else
//dootherstuff