PipedInputStream类close()方法 (PipedInputStream Class close() method)

  • close() method is available in java.io package.

    close()方法在java.io包中可用。

  • close() method is used to close this PipedInputStream and free all system resources linked with this stream.

    close()方法用于关闭此PipedInputStream并释放与此流链接的所有系统资源。

  • close() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    close()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • close() method may throw an exception at the time of closing the stream.

    close()方法在关闭流时可能会引发异常。

    IOException: This exception may throw when getting any input/output error while performing.

    IOException :在执行过程中遇到任何输入/输出错误时,可能引发此异常。

Syntax:

句法:

    public void close();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void close() method
// of PipedInputStream
import java.io.*;
public class CloseOfPIS {public static void main(String[] args) throws Exception {int val = 65;
try {// Instantiates PipedInputStream and
// PipedOutputStream
PipedInputStream pipe_in = new PipedInputStream();
PipedOutputStream pipe_out = new PipedOutputStream();
for (int i = 0; i < 3; ++i) {// By using write() method is to
// write the val to the stream pipe_out
pipe_out.write(val);
val++;
}
// By using close() method is to close
// the stream
pipe_in.close();
pipe_out.close();
// when we call read() after closing the stream
// will result an exception
for (int i = 0; i < 3; ++i) {// By using read() method is to
// read the integer and convert it into
// char
char ch = (char) pipe_in.read();
System.out.println("pipe_in.read(): " + ch);
}
} catch (Exception ex) {System.out.println("Stream Closed Before!!!!");
}
}
}

Output

输出量

Stream Closed Before!!!!

翻译自: https://www.includehelp.com/java/pipedinputstream-close-method-with-example.aspx

Java PipedInputStream close()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java receive_Java PipedInputStream receive()方法与示例

    PipedInputStream类receive()方法receive()方法在java.io包中可用. receive()方法用于接收内容的一个字节,当不再有剩余输入时它将阻塞. receive() ...

  3. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  6. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  7. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  8. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  9. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  10. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. Tensorflow |(1)初识Tensorflow
  2. linux两个文件修改主机名
  3. 动态规划-换钱最少货币数
  4. matlab激光散斑散射半径测量,激光散斑测量2011412225741
  5. C语言试题六之使字符串的前导*号不得多于n个;若多于n个,则删除多于的*号;若少于或等于n个,则什么也不做。字符串中间和尾部的*号不删除。
  6. 数据库迁移mysql到sqlserver_数据库迁移(sqlserver至mysql)
  7. Bootstrap 4:如何使顶部固定的Navbar保持在容器中而不拉伸?
  8. 泰山行宫碧霞元君祠_临清市泰山行宫碧霞元君祠5月4号(农历三月三十日)举行大型泰山奶奶接驾法会...
  9. 计算机应用基础形考作业3Excel部分,计算机应用基础形考3,Excel部分
  10. 7.2Python入门(三)
  11. android真实项目教程(二)——漫画App初构_by_CJJ
  12. 控制反转和依赖注入的理解(通俗易懂)_Spring 的本质系列之依赖注入_一点课堂(多岸学院)...
  13. Python3.6 安装pandas包的方法
  14. 十分钟教你学会vi编辑器使用方法(详细版)
  15. matlab求矩阵 均值、标准差、最大值以及reshape()函数
  16. LPDDR4 layout instruction
  17. 【Java 8 新特性】Java CompletableFuture thenApply()
  18. 算法导论为何被称为CLRS
  19. sencha touch 百度地图扩展(2014-6-24)(废弃 仅参考)
  20. 学历焦虑正在摧毁新一代测试工程师!学历不够如何破局?

热门文章

  1. java存储键值结构_java-键值存储为主数据库
  2. ?php php,PHP: Balises PHP - Manual
  3. 关于mmdetection上手的几点说明
  4. oracle 结果集已耗尽_java.sql.SQLException: 结果集已耗尽
  5. python图像识别代码_用Python进行简单图像识别(验证码)
  6. python virtualenv conda_在vscode中启动conda虚拟环境的思路详解
  7. c中获取python控制台输出_在真实的tim中用C捕获控制台python打印
  8. 计算机护理职称考试报名时间2015,护理职称考试怎么报名?
  9. ubunt16.04 安装3090显卡驱动 cuda cudnn pytorch
  10. Nginx主配置文件nginx.conf中文详解