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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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…