How can I determine if a file is a PDF file?

后端 未结 13 994
暖寄归人
暖寄归人 2020-12-24 11:57

I am using PdfBox in Java to extract text from PDF files. Some of the input files provided are not valid and PDFTextStripper halts on these files. Is there a clean way to ch

13条回答
  •  被撕碎了的回忆
    2020-12-24 12:16

    Pdf files begin "%PDF" (open one in TextPad or similar and take a look)

    Any reason you can't just read the file with a StringReader and check for this?

提交回复
热议问题