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.
reset()方法用于重置此流。 它将流重置到最近标记的位置。
reset() 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.
reset()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
reset() method may throw an exception at the time of resetting the stream.
reset()方法在重置流时可能会引发异常。
IOException: This exception may throw when getting any input/output error while writing to the output stream.
IOException :在写入输出流时遇到任何输入/输出错误时,可能引发此异常。
Syntax:
句法:
public void reset();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is void, it returns nothing.
此方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example
// of void reset() method of ObjectOutputStream
import java.io.*;
public class ResetOfOOS {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 writeByte() method is to
// write byte to the stream
obj_out_stm.writeByte(65);
// By using reset() method is to
// reset the stream
obj_out_stm.reset();
// Write another bytes to the
// stream
obj_out_stm.writeByte(66);
obj_out_stm.writeByte(67);
// By using flush() method is to
// flush the stream immediately
System.out.println("Stream Flushed...");
obj_out_stm.flush();
// By using readByte() method is to
// read the byte and convert it into
// char
for (int i = 0; i < 3; ++i) {char ch = (char) obj_in_stm.readByte();
System.out.println("ch: " + 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
输出量
Stream Flushed...
ch: A
ch: B
ch: C
Stream Shutdown...
翻译自: https://www.includehelp.com/java/objectoutputstream-reset-method-with-example.aspx
Java ObjectOutputStream reset()方法与示例相关推荐
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- java writebytes()_Java ObjectOutputStream writeBytes()方法与示例
ObjectOutputStream类writeBytes()方法writeBytes()方法在java.io包中可用. writeBytes()方法用于将给定的字符串作为字节序列写入. writeB ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- inputstream 关闭 java,Java ObjectInputStream close()方法与示例
ObjectInputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此ObjectInputStream并释放与此流链接的所有系统资源. cl ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- catalog java,Java Connection getCatalog()方法与示例
通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...
- filepermission java,Java FilePermission getActions()方法与示例
FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...
- java方法参数Bundle,Java ResourceBundle keySet()方法及示例
ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...
- java exec waitfor,Java Process waitFor()方法与示例
流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...
最新文章
- 第三十课.向量胶囊与动态路由
- 用python处理excel数据的优势-python数据分析相对于bi和excel的优势是什么?
- python中是干嘛的-学 Python 都用来干嘛的?
- 马哥教育第二十四ftp协议、vsftpd的高级应用、rpc概念及nfs的基本应用、samba及其基本应用...
- java处理文件路径windows与linux兼容问题
- MySQL create table as与create table like对比
- iOS Hacker 越狱后如何使用 root 运行应用
- Java 9中的新Regex功能
- [Leedcode][JAVA][第5题][最长回文子串][数组][动态规划]
- zznu 1996 : 正三角形和圆的爱情
- 计算机启动需输入两次密码,为什么我的电脑要2次启动才能启动我电脑设置了启动密码后就一定要2 爱问知识人...
- debian8.7.1安装zabbix3.2
- ftp网页服务器不允许匿名登录,我的FTP服务器不让匿名登陆,怎么办?
- php format tool,iFormatTool
- 简单的移动端打开pdf文件。
- 学习笔记4--惯性导航及总结
- Mugeda:代码分享
- python爬取淘宝数据魔方_淘宝数据魔方技术架构解析读后感
- js如何获取计算机当前时间,js获取当前系统时间实例代码
- 你的代码会说话吗?(上)
热门文章
- uboot引导linux内核,u-boot启动内核的几种方式
- c# 替换html注释,C# 替换div标签
- 安装php no permision,php安装过程中的No package ‘xxx’ found问题
- matlab bad apple,【bad apple】matlab制作矩阵苹果~
- android 电话号码标记,强化电话标记功能 360手机卫士3.0安卓版体验
- JDK源码解析之 java.lang.ThreadLocal
- 问题 B: 调整表中元素顺序(线性表)
- linux外接显示屏,关掉本身的笔记本电脑
- Kingback小组冲刺博客
- WinDbg 命令三部曲:(一)WinDbg 命令手册