【问题标题】:How to delete a pdf file if it does not contain text? [duplicate]如果pdf文件不包含文本,如何删除它? [复制]
【发布时间】:2013-11-12 18:31:42
【问题描述】:

我想删除所有不包含文本的 pdf 文件。我尝试使用 PdfBox。 方法 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 erase


    【解决方案1】:

    String 对象无法在 Java 中使用 == 进行比较。

    请使用String.equals() 方法。

    String s1 = "dat1";
    String s2 = "dat2";
    
    if(s1.equals(s2))
        //dostuff
    else
        //dootherstuff
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 2014-02-15
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多