Java ObjectOutputStream writeBytes()方法與示例

ObjectOutputStream類writeBytes()方法 (ObjectOutputStream Class writeBytes() method)

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

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

  • writeBytes() method is used to write the given string as a sequence of bytes.

    writeBytes()方法用于將給定的字符串作為字節序列寫入。

  • writeBytes() 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.

    writeBytes()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • writeBytes() method may throw an exception at the time of writing bytes.

    writeBytes()方法在寫入字節時可能會引發異常。

    IOException: This exception may throw when getting any input/output error while writing to the output stream.

    IOException :在寫入輸出流時遇到任何輸入/輸出錯誤時,可能引發此異常。

Syntax:

句法:

    public void writeBytes(String s);

Parameter(s):

參數:

  • String s – represents the string to be written.

    字符串s –表示要寫入的字符串。

Return value:

返回值:

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

該方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void writeBytes(String s) method of
// ObjectOutputStream
import java.io.*;
public class WriteBytesOfOOS {
public static void main(String[] args) throws Exception {
// Instantiates ObjectOutputStream , ObjectInputStream 
// FileInputStream and FileOutputStream
FileOutputStream file_out_stm = new FileOutputStream("D:\\includehelp.txt");
ObjectOutputStream obj_out_stm = new ObjectOutputStream(file_out_stm);
FileInputStream file_in_stm = new FileInputStream("D:\\includehelp.txt");
ObjectInputStream obj_in_stm = new ObjectInputStream(file_in_stm);
// By using writeBytes() method is to
// write the bytes to the stream		
obj_out_stm.writeBytes("Java");
obj_out_stm.flush();
// By using readByte() method is to 
// read the byte and convert it into
// char
for (int i = 0; i < 4; ++i) {
char ch = (char) obj_in_stm.readByte();
System.out.println("obj_in_stm.readByte(): " + ch);
}
// By using close() method is to 
// close all the streams 
System.out.println("Stream Shutdown... ");
file_in_stm.close();
file_out_stm.close();
obj_in_stm.close();
obj_out_stm.close();
}
}

Output

輸出量

obj_in_stm.readByte(): J
obj_in_stm.readByte(): a
obj_in_stm.readByte(): v
obj_in_stm.readByte(): a
Stream Shutdown... 

翻譯自: https://www.includehelp.com/java/objectoutputstream-writebytes-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379857.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379857.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379857.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何集中注意力(3)

如何集中注意力&#xff08;3&#xff09; [ 2008-10-20 10:15 ]by Glen Stansberry of LifeDev (feed). 集中注意力并不是一件很容易的事情&#xff0c;尤其是處在當前這個充滿誘惑和紛擾的世界里。下面是繼續告訴大家一些有幫助的方法&#xff1a; 7. Plan your day to the T…

Java——網絡編程三要素

* A:計算機網絡* 是指將地理位置不同的具有獨立功能的多臺計算機及其外部設備&#xff0c;通過通信線路連接起來&#xff0c;在網絡操作系統、網絡管理軟件及網絡通信協議的管理和協調下&#xff0c;實現資源共享和信息傳遞的計算機系統。* 其實我們這些網&#xff0c;之所以能…

python安全攻防---爬蟲基礎--re解析數據

0x01 re基礎 使用re模塊&#xff0c;必須先導入re模塊 import refindall()&#xff1a;匹配所有符合正則的內容&#xff0c;返回的是一個列表 import restr "我的電話&#xff1a;10086&#xff0c;女朋友電話&#xff1a;11011" list re.findall(\d,str) print…

BSP for good 3d engine

1.open sourcehttp://irrlicht.sourceforge.net/downloads/ 2.不錯的小材質http://www.permadi.com/tutorial/webgraph/index.html 3.java bsp display(demo):http://www.symbolcraft.com/graphics/bsp/index.php http://www.faqs.org/faqs/graphics/bsptree-faq/ 4.a bps ill…

Java InputStreamReader getEncoding()方法及示例

InputStreamReader類的getEncoding()方法 (InputStreamReader Class getEncoding() method) getEncoding() method is available in java.io package. getEncoding()方法在java.io包中可用。 getEncoding() method is used to get the encoding name avail for this InputStrea…

python安全攻防---爬蟲基礎---BeautifulSoup解析

0x01 基礎 使用bs4首先要安裝&#xff0c;安裝后導入 import bs4bs對象有兩個方法&#xff0c;一個是find&#xff0c;另一個是find_all find&#xff08;標簽名&#xff0c;屬性值&#xff09;&#xff1a;只返回一個&#xff0c;返回也是bs對象&#xff0c;可以繼續用find…

DataRabbit 3.1發布,完全支持SqlServer2005/2008

增加了對SqlServer2005/2008的新的數據類型的支持&#xff0c;如uniqueidentifier、time、sql_variant等。另外&#xff0c;EntityCreator也一起更新--不再強迫為Entity生成ToString&#xff08;&#xff09;方法&#xff0c;使用者可以主動選擇是否要生成。 DataRabbit 3.1 下…

Java——Socket通信原理

* Socket通信原理圖解* A:Socket(中文翻譯為&#xff1a;電源插座)套接字概述* 網絡上具有唯一標識的IP地址和端口號組合在一起才能構成唯一能識別的標識套接字* 通信的兩端都有Socket(兩端都是電源插座&#xff0c;中間是啥&#xff1f;不就是電線啦&#xff0c;電…

asp.net鏈接mysql數據庫------------【個人收集】

在web.config文件中添加如下樣式的數據庫鏈接字符串&#xff1a; <add name"dbconnection" connectionString"DataBasedatabasename;Server127.0.0.1;Uid用戶名;Pwd密碼;character setgbk;" providerName"MySql.Data.MySqlClient"/></c…

sql2005 遠程連接

SQL Server 2005 不允許遠程連接解決方法轉載于:https://www.cnblogs.com/lcq135/archive/2008/11/06/1328380.html

Java GregorianCalendar computeTime()方法與示例

GregorianCalendar類computeTime()方法 (GregorianCalendar Class computeTime() method) computeTime() method is available in java.util package. java.util包中提供了computeTime()方法 。 computeTime() method is used to compute the calendar fields to the calendar …

python安全攻防---scapy基礎---計算機網絡各層協議

網絡層次劃分 比較常用的是TCP/IP五層協議。 0x01應用層 應用層是網絡應用程序以及它們的應用層協議存留的地方。應用層協議和應用程序直接掛鉤 DHCP(Dynamic Host Configuration Protocol)動態主機分配協議&#xff0c;使用 UDP 協議工作&#xff0c;主要有兩個用途&#xf…

一點心得(0)

1, 在C中&#xff0c;如果棧里的空間不足的話&#xff0c;要考慮用new命令在堆上動態生成數據&#xff0c;比如說保存所有無符號整數型的bitset&#xff0c;得用bitset<UINT_MAX1>* bs new bitset<UINT_MAX1>;來聲明定義&#xff0c;最后別忘了delete掉。 2, make…

Java——UPD輸出及優化再優化

* UPD傳輸不區分客戶端跟服務端&#xff0c;* 這里用Send和Receive這兩個方法決定誰發誰收 * 1.發送Send * 創建DatagramSocket,隨機端口號* 創建DatagramPacket,指定數據、長度、地址、端口* 創建DatagramSocket發送DatagramPacket* 關閉DatagramSocket 代碼如下&…

FLEX:圖形制作皮膚vs編程制作皮膚

Styles&#xff08;樣式&#xff09;提供了一個可以自定義flex外觀的層.可以圖形制作皮膚&#xff0c;也可以編程實現. &#xff08;小小菜鳥翻譯&#xff09; 圖形制作皮膚的 優點是 很容易實現&#xff0c;通過位圖&#xff0c;矢量圖&#xff0c;swf。 缺點是功能有限。…

Java文件類boolean canExecute()方法(帶示例)

文件類boolean canExecute() (File Class boolean canExecute()) This method is available in package java.io.File.canExecute(). 軟件包java.io.File.canExecute()中提供了此方法。 This method is used to execute the file and the file is represented by the abstract …

python安全攻防---scapy使用

導入scapy包 from scapy.all import *構造包 a Ether()/IP(dst114.114.114.114)/TCP(dport80)/應用層數據我們如果記不得每個包的選項使&#xff0c;可以使用show()來查看 print(a.show())發送包 sr(IP(dst‘192.168.1.0/24’)/TCP(dport(1,65535)), timeout2) &#xff1…

唉!

學習到后面時&#xff0c;再返回看了一下前面學過的&#xff0c;發現以前學過&#xff0c;看不懂的東西現在能看懂了…… &#xff01;不過 為什么在剛學時就是不懂&#xff0c;這樣 不就老是慢一拍嗎&#xff1f;唉&#xff01;&#xff01;轉載于:https://www.cnblogs.com/ni…

Java—— TCP協議(相關代碼實現以及相關優化)

代碼運行的時候先運行服務端&#xff0c;然后在運行客戶端 * TCP協議&#xff1a;* 1&#xff0c;客戶端* 創建Socket連接服務器(指定IP地址&#xff0c;端口號)通過IP地址找到對應的服務器* 調用Socket的getInputStream()和getOutputStream()方法獲取和服務器端相連…

什么是adsense 想通過廣告掙錢的看過來

Adsense的含義Google AdSense是由Google公司推出的針對網站主&#xff08;簡稱發布商&#xff09;的一個互聯網廣告服務。AdSense是個合成詞。其中ad是“廣告”之意&#xff0c;sense是“感知”之意&#xff0c;綜合起來的意思就是相關廣告。Google通過程序來分析網站的內容&am…