Java - Read all pdf file in the folder

3.2k views Asked by At
try
        {            
            PdfReader reader = new PdfReader(RESULT1);
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2));
            AcroFields form = stamper.getAcroFields();
            String name = form.getField("Text1");//Check Box 1  
            stamper.close();
            reader.close();

            FileInputStream file = new FileInputStream(new File("//Users//"+ usr +"//Desktop//TNA//input//FR-OPS-030 Master Training Plan_Rev4.xls"));
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            HSSFSheet sheet = workbook.getSheet("Sheet1");//    getSheetAt(0);

            HSSFRow row = sheet.createRow((short) 0);    
            HSSFCellStyle style = workbook.createCellStyle();
            style.setFillForegroundColor(HSSFColor.DARK_BLUE.index);
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

            HSSFRow row1 = sheet.createRow(7);
            HSSFCell name_c1 = row1.createCell(0);
            name_c1.setCellValue(name);
            name_c1.setCellStyle(style);

            file.close();

            FileOutputStream outFile =new FileOutputStream(new File("//Users//"+ usr +"//Desktop//TNA//output//FR-OPS-030 Master Training Plan_Rev41w.xls"));
            workbook.write(outFile);
            outFile.close();
        }
        catch(Exception ex)
        {
           System.out.println(ex);                
        }

I used the code to read PDF file from the folder. It's working fine for single document but I have multiple files in the folder. How do I read PDF multiple files. Please advice

1

There are 1 answers

0
MadProgrammer On BEST ANSWER

You could start by taking a look at java.io.File which has methods for listing files...

Or, if you're using Java 7+, you could take a look at the enhanced File I/O API