★★Java質問・相談スレッド184★★ (371レス)
上下前次1-新
130: (テテンテンテン MM0e-c/TO) 2023/02/26(日)00:02 ID:F7MFR7BvM(1/2) AAS
フォルダの中にある各ファイルを対象とした処理を書きたいのですが、
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以外を使用するべきでしょうか?
上下前次1-新書関写板覧索設栞歴
あと 241 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ
ぬこの手 ぬこTOP 0.011s