★★Java質問・相談スレッド184★★ (371レス)
★★Java質問・相談スレッド184★★ http://mevius.5ch.net/test/read.cgi/tech/1632019965/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
必死チェッカー(本家)
(べ)
自ID
レス栞
あぼーん
リロード規制
です。10分ほどで解除するので、
他のブラウザ
へ避難してください。
130: デフォルトの名無しさん (テテンテンテン MM0e-c/TO) [] 2023/02/26(日) 00:02:46.88 ID:F7MFR7BvM フォルダの中にある各ファイルを対象とした処理を書きたいのですが、 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以外を使用するべきでしょうか? http://mevius.5ch.net/test/read.cgi/tech/1632019965/130
132: デフォルトの名無しさん (テテンテンテン MM0e-c/TO) [] 2023/02/26(日) 02:49:11.03 ID:F7MFR7BvM >>131 ありがとうございます。 try (Stream<Path> stream = Files.list(Paths.get(path))) { File[] inputFiles = stream.filter(Files::isRegularFile).toArray(File[]::new); Iterator<File> i = Arrays.asList(inputFiles).iterator(); while (i.hasNext()) {}} のように、つなげて?書いてみたのですが Exception in thread "main" java.lang.ArrayStoreException: arraycopy: element type mismatch: can not cast one of the elements of java.lang.Object[] to the type of the destination array, java.io.File とエラーが表示されるので、もう少し調べてみます。 http://mevius.5ch.net/test/read.cgi/tech/1632019965/132
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.024s