Java PipedOutputStream connect()方法与示例
PipedOutputStream类的connect()方法 (PipedOutputStream Class connect() method)
connect() method is available in java.io package.
connect()方法在java.io包中可用。
connect() method is used to cause this PipedOutputStream to be connected to the given PipedInputStream when this PipedOutputStream is not previously connected to any of the other PipedInputStream.
当此PipedOutputStream先前未连接到任何其他PipedInputStream时,使用connect()方法使此PipedOutputStream连接到给定的PipedInputStream。
connect() 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.
connect()方法是一种非静态方法,仅可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。
connect() method may throw an exception at the time of connecting the stream.
connect()方法在连接流时可能会引发异常。
IOException: This exception may throw when getting any input/output error or pipe not connected properly, or stream closed.
IOException:当出现任何输入/输出错误或管道未正确连接或流关闭时,可能引发此异常。
Syntax:
句法:
public void connect(PipedInputStream pis);
Parameter(s):
参数:
PipedInputStream pis – represents the piped input stream to connect to this piped output stream.
PipedInputStream pis –表示连接到此管道输出流的管道输入流。
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example
// of void connect(PipedInputStream pis) method of
// PipedOutputStream
import java.io.*;
public class ConnectOfPOS {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();
// By using connect() method is to
// connect this pipe_out to the given pipe_in
pipe_out.connect(pipe_in);
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++;
}
for (int i = 1; i < 4; ++i) {// By using read() method is to read
// the integer and converted into int
char ch = (char) pipe_in.read();
System.out.println("pipe_in.read(): " + ch);
}
// By using close() method is to close
// the stream
pipe_in.close();
pipe_out.close();
} catch (Exception ex) {System.out.println(ex.toString());
}
}
}
Output
输出量
pipe_in.read(): A
pipe_in.read(): B
pipe_in.read(): C
翻译自: https://www.includehelp.com/java/pipedoutputstream-connect-method-with-example.aspx
Java PipedOutputStream connect()方法与示例相关推荐
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- catalog java,Java Connection getCatalog()方法与示例
通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...
- filepermission java,Java FilePermission getActions()方法与示例
FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...
- java方法参数Bundle,Java ResourceBundle keySet()方法及示例
ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...
- java exec waitfor,Java Process waitFor()方法与示例
流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...
- java arraylist.add(),Java ArrayList add()方法与示例
ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...
- java rollback用法,Java Connection rollBack()方法与示例
回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...
最新文章
- 实验:3*3卷积核10分类9*9图片卷积核数量最优值
- 视频编码中的RC(rate control)是什么?码率控制 CBR (Constant Bit Rate)、VBR (Variable Bit Rate)
- Tomcat 服务器server.xml,web.xml的关键参数配置
- 知识图谱理论与实践(以问答系统为例)
- 什么是BSP工程师?
- Unable to round-trip http request to upstream错误
- 华邦电子2022年3月营收为新台币92.17亿元
- grDevices | R语言中的配色方法汇总(Ⅱ-2)
- shutdown immediate ,无法关闭数据库的解决方案
- 新Linux木马发现:每30秒截图并用麦克风录音
- Akka的Actor层级结构《seven》译
- 1125: 上三角矩阵的判断
- 随机生成10位数QQ号.c
- php数据传输神器,「curl」PHP中的传输神器
- 国瀚实业|春节投资,这些理财的坑要注意
- rtx3060ti、rtx3060和rtx2080ti 参数对比哪个好 差距大不大
- Chapter 9 Measurement Bias
- [藏]疯狂的极端,20款IM,UI比比看
- 折叠留言楼层,递归无线循环
- selenium 模拟 填问卷 问卷星
热门文章
- java 结构体数组初始化_C数组结构体联合体快速初始化
- 炉石传说服务器维护有补偿吗,炉石传说维护公告全文及具体补偿方案 炉石数据回档怎么补偿?...
- php5.6扩展编写,php 5.6版本中编写一个PHP扩展的简单示例
- mysql架构组成_第 2 章 MySQL 架构组成
- 0-安装Vagrant和使用
- C#统计字符出现的个数【C#】
- 问题 I: 连通块计数
- 016 pickle
- 五阿哥钢铁电商平台Docker容器云平台建设实践——你想知道的都在这里!
- Oracle Linux 6.5 RPM安装Mysql 5.7.11