刷新输入流:java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2332739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:39:09  来源:igfitidea点击:

flushing input stream: java

java

提问by Terman

Is there a way to flush the input stream in Java, perhaps prior to closing it? In relation to iteratively invoking the statements below, while reading several files on disk

有没有办法在 Java 中刷新输入流,也许是在关闭它之前?关于在读取磁盘上的多个文件时反复调用以下语句

InputStream fileStream = item.openStream();
fileStream.close;

回答by spa

InputStreamcannot be flushed. Why do you want to do this? OutputStreamcan be flushed as it implements the interface Flushable. Flushing makes IMHO only sense in scenarios where data is written (to force a write of buffered data). Please see the documentationof Flushablefor all implementing classes.

InputStream无法冲洗。你为什么要这样做? OutputStream可以在它实现接口时刷新Flushable。冲洗使恕我直言仅在写入数据的情况下有意义(以强制写入缓冲数据)。请参阅该文档Flushable所有实现类。