尝试从单词doc中获取特定数据时获取ArrayIndexOutofBoundException [重复]

问题描述 投票:0回答:1

我正在尝试从目录中的Word文档列表中读取内容,并从所有文件中获取特定值“ Summary”。这是我的下面的代码。当它试图获取第二个文件的值时,它抛出Array Index out of bound exception

有人可以帮我摆脱这个问题

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");
    }    
}
java arrays list indexoutofboundsexception
1个回答
0
投票

异常日志将有助于识别引发异常的行。似乎如果没有匹配的文本,即“ Summary:”。

您可能要打开第二个文件并验证该文本是否存在。

© www.soinside.com 2019 - 2024. All rights reserved.