I am trying to read contents from list of word documents in a directory and getting specific value which is "Summary" from all the files. Here is my code below. When it tries to get the 2nd file's value its throwing Array Index out of bound exception
Can someone help me out to get rid of this issue
public static void main(String[] args) throws IOException {
File folder = new File("C:\\Kiruba\\Test Folder\\Admin\\");
File[] listfiles = folder.listFiles();
for(int i = 0; i < listfiles.length; i++) {
if(listfiles[i].isFile()) {
FileInputStream fis = new FileInputStream(listfiles[i]);
XWPFDocument docx = new XWPFDocument(fis);
List<XWPFParagraph> paragraphlist = docx.getParagraphs();
for(XWPFParagraph paragraph : paragraphlist) {
String summary = paragraph.getText().split("Summary: ")[1];
System.out.println(summary);
}
}
else
System.out.println("There is no files in the directory");
}
}