Java ObjectOutputStream writeChar()方法与示例

ObjectOutputStream类writeChar()方法 (ObjectOutputStream Class writeChar() method)

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

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

  • writeChar() method is used to write 2 bytes of a character value.

    writeChar()方法用于写入2个字节的字符值。

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

    writeChar()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • writeChar() method may throw an exception at the time of writing the character.

    writeChar()方法在编写字符时可能会引发异常。

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

    IOException :在写入输出流时遇到任何输入/输出错误时,可能引发此异常。

Syntax:

句法:

    public void writeChar(int value);

Parameter(s):

参数:

  • int value – represents an integer that denotes a character to be written.

    int value –表示要写入的字符的整数。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of void writeChar(int value) method of
// ObjectOutputStream
import java.io.*;
public class WriteCharOfOOS {
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("C:\\includehelp.txt");
ObjectInputStream obj_in_stm = new ObjectInputStream(file_in_stm);
// By using writeChar() method is to
// write the char to the stream		
obj_out_stm.writeChar('a');
obj_out_stm.writeChar('d');
obj_out_stm.writeChar('e');
obj_out_stm.writeChar('b');
obj_out_stm.flush();
// By using readChar() method is to 
// read the char 
for (int i = 0; i < 4; ++i) {
char ch = obj_in_stm.readChar();
System.out.println("obj_in_stm.readChar(): " + 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.readChar(): a
obj_in_stm.readChar(): d
obj_in_stm.readChar(): e
obj_in_stm.readChar(): b
Stream Shutdown...

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

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

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

相关文章

虚拟机的管理

我们采用虚拟机的原因是什么呢&#xff0c;很简单就俩字&#xff1a; 节能 1. 管理虚拟机的命令&#xff1a; virt-manager开启虚拟机管理器virsh list显示正在运行的虚拟机virsh list --all查看所有虚拟机virsh start desktop打开虚拟机virsh shutdown desktop正常关闭虚拟机…

mybatis对java自定义注解的使用——入门篇

转自&#xff1b;https://www.cnblogs.com/sonofelice/p/4980161.html 1. 最近在学习spring和ibatis框架。 以前在天猫实习时做过的一个小项目用到的mybatis&#xff0c;在其使用过程中&#xff0c;不加思索的用了比较原始的一种持久化方式&#xff1a; 在一个包中写一个DAO的接…

Java BigDecimal toBigIntegerExact()方法(带示例)

BigDecimal类的toBigIntegerExact()方法 (BigDecimal Class toBigIntegerExact() method) toBigIntegerExact() method is available in java.math package. toBigIntegerExact()方法在java.math包中可用。 toBigIntegerExact() method is used to convert this BigDecimal int…

Linux中的软件管理

1. 使用已有的网络安装资源安装软件 cd /etc/yum.repos.d/ (移动到yum源指向的文件配置目录下&#xff09; vim westos.repo &#xff08;新建文件&#xff0c;yum下后缀必须为.repo) 编辑这个文件里面写 [redhat] &#xff08;软件仓库名称&#xff09; namefirefox &#x…

楚留香ai人脸识别_戴口罩居然也能人脸识别?这些AI黑科技真的藏不住了.........

当人工智能遇见影像技术&#xff0c;将会释放出多少意想不到的巨大能量&#xff1f;「喔图知图实验室」瞄准当下的影像痛点&#xff0c;持续发力升级AI黑科技&#xff0c;带来两大必杀技——人脸识别再度升级、AI智能旋转校正。戴口罩也能识别——人脸识别升级戴口罩人脸识别如…

android--------Popupwindow的使用

2019独角兽企业重金招聘Python工程师标准>>> PopupWindow在Android.widget包下&#xff0c;项目中经常会使用到PopupWindow做菜单选项&#xff0c; PopupWindow这个类用来实现一个弹出框&#xff0c;可以使用任意布局的View作为其内容&#xff0c;这个弹出框是悬浮…

使用JavaScript中的示例的escape()函数

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string. 在通过网络传输数据或有时将数据保存到数据库…

安装虚拟机的脚本

1. 先安装生成自动安装脚本的工具 yum install system-config-kickstart -y 2. 打开这个软件 system-config-kickstart 基本设置&#xff1a;更改时区为上海&#xff0c;设置root用户密码 2&#xff09;设置安装方法为网络安装&#xff0c;将共享的镜像文件地址正确填写 3&…

小小小游戏

写着玩 FlappyBird 视频:https://pan.baidu.com/s/1sljIR5z 游戏:https://pan.baidu.com/s/1ge8j7Ej 项目:https://pan.baidu.com/s/1eSysxpw Breakout 视频:https://pan.baidu.com/s/1gfhv4hd 项目:https://pan.baidu.com/s/1hs8xPly QBert 视频:https://pan.baidu.com/s/1s…

go在方法中修改结构体的值_[Go]结构体及其方法

结构体类型可以包含若干字段&#xff0c;每个字段通常都需要有确切的名字和类型。也可以不包含任何字段&#xff0c;这样并不是没有意义的&#xff0c;因为还可以为这些类型关联上一些方法&#xff0c;这里可以把方法看作事函数的特殊版本。函数事独立的程序实体&#xff0c;可…

to_number用法示例_Number()函数以及JavaScript中的示例

to_number用法示例Number()函数 (Number() function) Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert the object in a number – it returns "NaN". (Rea…

系统延时任务及定时任务

1. 系统延时任务&#xff1a; at相关命令 at time 设定任务执行时间at> rm -fr /mnt/* 任务动作at> <EOT> <<ctrld 执行任务at的命令&#xff1a; -l ##查看任务列表-c …

cpn tools查看运行时间_Jmeter在Linux下的运行测试

一、JMeterApache JMeter是Apache组织开发的基于Java的压力测试工具。用于对软件做压力测试&#xff0c;它最初被设计用于Web应用测试&#xff0c;但后来扩展到其他测试领域。1.1、JMeter的作用能够对HTTP和FTP服务器进行压力和性能测试&#xff0c; 也可以对任何数据库进行同样…

css div滚动_如何使用CSS创建可垂直滚动的div?

css div滚动Introduction: 介绍&#xff1a; Dealing with divs has become a regularity and divs are used for many purposes like to structure our code and to segregate our various sections of codes. Besides, we are also aware of many properties that we can im…

Linux中磁盘分区的管理

1. 本地存储设备的识别 fdisk -l真实存在的设备cat /proc/partitions系统识别的设备blkid系统可使用的设备df系统正在挂载的设备 真实存在的设备不一定可识别&#xff0c;识别到的的设备不一定可使用 2. 设备的挂载和卸载 1&#xff09;设备名称 /dev/xdx …

python中时间的加减_python日期加减

python中关于时间和日期函数的常用计算总结 python中关于时间和日期函数有time和datatime 1.获取当前时间的两种方法: import datetime,time now = time.strftime("%Y-%m-%d %H:%M:%S") print now now = datetime.datetime.now()... 文章 技术小胖子 2017-11-08 848…

bst 删除节点_在BST中删除大于或等于k的节点

bst 删除节点Problem statement: 问题陈述&#xff1a; Given a BST and a value x, write a function to delete the nodes having values greater than or equal to x. The function will return the modified root. 给定一个BST和一个值x &#xff0c;编写一个函数删除值大…

游戏架构之二(转)

棋牌类游戏常用架构&#xff1a; 我从事过4年的棋牌类游戏开发&#xff0c;使用过的架构大致如上&#xff0c;各模块解释如下。 LoginServer&#xff1a; 登陆服务器&#xff0c;主要负责player 的登陆请求&#xff0c;验证player的合法性&#xff0c;为合法的player分配sessio…

对lvm介绍

1. 什么是LVM LVM是 Logical Volume Manager&#xff08;逻辑卷管理&#xff09;的简写&#xff0c;它是Linux环境下对磁盘分区进行管理的一种机制&#xff0c;用户在无需停机的情况下可以方便地调整各个分区大小。 lvm中的一些常见符号及意义 pv物理卷被lv命令处理过的物理分…

pythonweb自动化测试实例_[转载]python webdriver自动化测试实例

python webdriver自动化测试初步印象以下示例演示启动firefox&#xff0c;浏览google.com,搜索Cheese&#xff0c;等待搜索结果&#xff0c;然后打印出搜索结果页的标题from selenium import webdriverfrom selenium.common.exceptions import TimeoutExceptionfrom selenium.w…