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.pswp.cn/news/541878.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541878.shtml
英文地址,請注明出處:http://en.pswp.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;下面我整理了一下…