フォルダの中にある各ファイルを対象とした処理を書きたいのですが、
File[] inputFiles = stream.toArray(File[]::new);
の行で
Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed
がでます。

try (Stream<Path> stream = Files.list(Paths.get(path))) {
stream.filter(Files::isRegularFile);
File[] inputFiles = stream.toArray(File[]::new);
Iterator<File> i = Arrays.asList(inputFiles).iterator();
while (i.hasNext()) {}
} catch (IOException e) { e.printStackTrace(); }

が試そうとしているコードになりますが、stream以外を使用するべきでしょうか?