I’m making an android app using eclipse. With that app it want to parse a PDF using iText. But I don’t know in advance whether the PDF is already available or not. And now, when iText starts parsing the PDF it force closes, simply because the PDF doesn’t exist (yet). So my question is how can I prevent that from happening? Can I check (using iText or using something else) whether the PDF is available or not.
This is my code so far:
int numberOfPages = readerTest.getNumberOfPages();
numberOfPages = numberOfPages + 1;
for (int page = 1; page < numberOfPages; page++){
try {
contentTest1Page = PdfTextExtractor.getTextFromPage(readerTest, page);
contentTest = contentTest + contentTest1Page;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Thank You!
Use
java.io.Fileand theexists()method to see if a file exists.