Java PipedInputStream connect()方法与示例

PipedInputStream类的connect()方法 (PipedInputStream Class connect() method)

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

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

  • connect() method is used to cause this PipedInputStream to be connected to the given PipedOutputStream when the PipedInputStream is not previously connected to any of the other PipedOutputStream.

    当PipedInputStream先前未连接到任何其他PipedOutputStream时,使用connect()方法使此PipedInputStream连接到给定的PipedOutputStream。

  • 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 while performing.

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

Syntax:

句法:

    public void connect(PipedOutputStream pos);

Parameter(s):

参数:

  • PipedOutputStream pos – represents the PipedOutputStream to connect to this PipedInputStream.

    PipedOutputStream pos –表示要连接到此PipedInputStream的PipedOutputStream。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of void connect(PipedOutputStream pos)
// method of PipedInputStream
import java.io.*;
public class ConnectOfPIS {
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_in to the given pipe_out
pipe_in.connect(pipe_out);
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++;
}
// 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);
}
// 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/pipedinputstream-connect-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541878.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java写手机游戏_如何将自己编写的JAVA小游戏写到手机里?

2019-06-19怎么用java编写获取星期几的程序&#xff1f;import java。util。*; public class WeekDay { Calendar date Calendar。getInstance(); private int getMaxDate(int moth){ moth moth -1; if(moth > 12 || moth < 0){ System。 out。println("输入月份错…

Java PipedInputStream receive()方法与示例

PipedInputStream类的receive()方法 (PipedInputStream Class receive() method) receive() method is available in java.io package. receive()方法在java.io包中可用。 receive() method is used to receive a byte of content and it will block when no more input remain…

java去除重复对象_Java19-2 集合类去除重复对象

List独有方法&#xff1a;import java.util.ArrayList;import java.util.List;public class ListTest2 {public static void main(String[] args) {List listnew ArrayList();list.add("abc1");list.add("abc2");list.add("abc1");list.add(&quo…

SSM框架整合中遇到重复的问题Ambiguous handler methods mapped for HTTP

严重: Servlet.service() for servlet [spring] in context with path [/ssmDemo] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path /init.do: {public java.lang.String …

Java ObjectStreamClass lookup()方法与示例

ObjectStreamClass类lookup()方法 (ObjectStreamClass Class lookup() method) lookup() method is available in java.io package. lookup()方法在java.io包中可用。 lookup() method is used to lookup the descriptor for a class that can be serialized. lookup()方法用于…

java default parameter_JAVA菜鸟入门(7) default parameter , float/double vs BigDecimal

1 java的允许函数的默认参数吗?java不支持类似C那样&#xff0c;为函数设定默认参数&#xff0c;所以需要做的事情是&#xff0c;自己用函数重载的方式进行模拟。如下public class FFOverload {public String getName(String givenName,String familyName){return givenName&…

gitlab修改默认端口

部署gitlab的时候&#xff0c;一启动&#xff0c;发现80和8080端口已经被占用&#xff0c;无奈&#xff0c;只得先将监听80端口的nginx和监听8080端口的jenkins停止。这会儿有空&#xff0c;琢磨一下如何修改gitlab的默认端口。 修改主要分为两部分&#xff0c;一部分是gitlab总…

Java ObjectOutputStream reset()方法与示例

ObjectOutputStream类reset()方法 (ObjectOutputStream Class reset() method) reset() method is available in java.io package. reset()方法在java.io包中可用。 reset() method is used to reset this stream. It reset the stream to the position marked most recently. …

Excel 自定义关闭按钮

遇到过这样一个需求&#xff0c;是在excel关闭的时候&#xff0c;不要excel本身的保存窗口&#xff0c;只用自定义的. 这个的需要第一&#xff0c;是点击关闭时候触发&#xff0c; 第二&#xff1b;触发后&#xff0c;不能还是弹出那个窗口 第三&#xff1a;取消后&#xff0c;…

Java OutputStreamWriter close()方法与示例

OutputStreamWriter类close()方法 (OutputStreamWriter Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to first flush before closing the stream and the method write() or flush() invok…

深入理解Netscaler INat

深入理解Netscaler INatNetscaler的INat主要是用作基于目的地址的转换&#xff0c;将client访问的公网IP通过Netscaler转换成服务器的私网IP&#xff0c;与DNAT作用类似。由于Netscaler默认的工作机制就是同时做源IP&#xff1a;【源端口】目的IP&#xff1a;【目的端口】的转换…

java 方法 示例_Java语言环境getDisplayCountry()方法与示例

java 方法 示例区域设置类getDisplayCountry()方法 (Locale Class getDisplayCountry() method) Syntax: 句法&#xff1a; public final String getDisplayCountry();public String getDisplayCountry(Locale lo);getDisplayCountry() method is available in java.util pack…

格力电器Java面试题_JAVA设计模式学习--工厂模式

今天谈一下对工厂模式学习的总结。看完视频和文章之后要自己表述工厂模式&#xff0c;总是感觉无从说起&#xff0c;不知道怎么去定义工厂模式&#xff0c;反复看了几遍之后终于理解一点。自己理解工厂模式是通过这两种模式的特点来理解和定义的&#xff0c;首先工厂模式有简单…

为什么玩我的世界老提示Java se错误_我的世界error错误信息 error could解决方法

我的世界是一个及其开放的沙盒游戏&#xff0c;而在这个游戏中有不少的问题&#xff0c;比如说遇到error该如何解决呢&#xff0c;看小编给大家带来的我的世界error错误的解决方法&#xff0c;希望大家喜欢。error应用程序错误信息。包括“Error:Unable to access jarfile mcpc…

Tomcat 服务器只能存有一个正在运行的项目

即使新建了一个new project &#xff08;在同一个工作空间&#xff09;&#xff0c;启动Tomcat 还是会出现先前&#xff08;工程名&#xff09;一样的问题/异常。 【原因】&#xff1a; 在底下Server 那里——Tomcat 7.X 底下会有很多工程名&#xff0c;它会纪录&#xff01;所…

Java Collections singletonMap()方法与示例

集合类singletonMap()方法 (Collections Class singletonMap() method) singletonMap() method is available in java.util package. singletonMap()方法在java.util包中可用。 singletonMap() method is used to return an immutable map (i.e. immutable map is a map that c…

java访问登录网页_===java怎样访问需要登录才能查看的网页????急!!===...

java中可以用java.net包下的东西访问网页&#xff0c;但是有的网页要求用户先输入用户名和密码才能查看&#xff0c;这些网页java怎么访问呢&#xff1f;&#xff1f;&#xff1f;注意&#xff1a;我说的要输入用户名和密码不是浏览器弹出一个框的那种&#xff0c;而是象csdn这…

javascript OOP(下)(九)

一、javascript模拟重载 java中根据参数类型和数量的区别来实现重载&#xff0c;javascript弱类型&#xff0c;没有直接的机制实现重载&#xff0c;javascript中参数类型不确定和参数个数任意&#xff0c;通过判断实际传入的参数的个数来实现重载。 <script> function Pe…

java calendar_Java Calendar getDisplayNames()方法与示例

java calendar日历类的getDisplayNames()方法 (Calendar Class getDisplayNames() method) getDisplayNames() method is available in java.util package. getDisplayNames()方法在java.util包中可用。 getDisplayNames() method is used to return Map that contains all fie…

Linux如何查找大文件或目录总结

转载&#xff1a;http://www.cnblogs.com/kerrycode/p/4391859.html 在Windows系统中&#xff0c;我们可以使用TreeSize工具查找一些大文件或文件夹&#xff0c;非常的方便高效&#xff0c;在Linux系统中&#xff0c;如何去搜索一些比较大的文件呢&#xff1f;下面我整理了一下…