Hi I just wanted to know what is wrong with my code and how can I improve it as it throws an error "stream has already been operated upon or closed" thank you here is my code:
Stream<String> stream = Files.lines(path)
stream.filter(item -> !item.contains("String")).forEach(item -> {
Pattern pattern = Pattern.compile(REGEX);
Matcher matcher = pattern.matcher(item);
if (!stream.filter(items -> items.length() > 12).collect(Collectors.toList()).isEmpty() == true) {
log.error("Item must not exceed 12 numbers {}", item);
streamMessage.set("Items must not exceed 12 numbers");
}
else if(matcher.matches() == true){
log.error("Invalid String format {}", item);
streamMessage.set("Invalid String format");
}
});
I wanted to loop inside the file and check per line if the characters there exceeded 12 characters or not
stream.close(). On the next iteration, the stream access will throw the exception.stream.close()is unnecessary, but it's not the cause of the error.