如何检查 ArrayList 的所有索引中是否没有文件?

How to check if the all the indexes of an ArrayList has no file in them?

我搜索了一下,没有找到类似的问题。 我想检查 ArrayList 的所有索引中是否没有文件(文件在它们的路径中不存在),显然这必须通过 for-loopboolean 来完成,所以我希望 boolean 像这样:

如果所有索引中都没有文件boolean为真。

如果一个或多个或所有索引的路径中有文件 boolean 则为 false。

使用下面的方法我有一个问题,如果其中一个索引(或者我应该说第一次出现)没有文件条件它是真的,但这不是我想要的,我希望它是真的仅当 所有索引中都没有文件时。

for (int i = 0; i < logopaths.size(); i++) {
            String s = logopaths.get(i);
            File file = new File(s);
            boolean exists = file.exists();
            if (exists){
                // do somethng
            } else {
                // do some other thing
            }
        }

这里 (:

// Array of logo paths
ArrayList<String> logoPaths = new ArrayList<>();

// File variable declaration
File file = null;
// The flag which indicates all the file paths are exists
boolean flag = ture;

for (int i = 0; i < logoPaths.size(); i++) {
    // Creating a file instance in order to get access to file operations
    file = new File(logoPaths.get(i));
    
    // If one file exists the flag will be false and we will break the for loop. 
    // If all the files are not exists the flag will stay true.
    if (file.exists()) {
        flag = false;
        break;
    }
}

或者把它变成一个方法:

    public boolean fileFound(List<String> logopaths) {
        boolean atLeastOneFileExists = false;
        for (int i = 0; i < logopaths.size() && !atLeastOneFileExists; i++) {
            String s = logopaths.get(i);
            File file = new File(s);
            atLeastOneFileExists = file.exists();
        }
        return atLeastOneFileExists;
    }