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

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

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

相关文章

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;下面我整理了一下…

java编写简单邮件_Javamail,编写简单的程序发送邮件

代码&#xff1a;package com.dai.mail; import java.util.Properties; import javax.activation.DataHandler; import javax.activation.FileDataSource; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.In…

java calendar_Java Calendar getLeastMaximum()方法与示例

java calendarCalendar类的getLeastMaximum()方法 (Calendar Class getLeastMaximum() method) getLeastMaximum() method is available in java.util package. getLeastMaximum()方法在java.util包中可用。 getLeastMaximum() method is used to get the least maximum value …

Shell 标准输入、输出和错误

防伪码&#xff1a;桃花潭水深千尺&#xff0c;不及汪伦送我情。文件描述符&#xff08;fd&#xff09;&#xff1a;文件描述符是一个非负整数&#xff0c;在打开现存文件或新建文件时&#xff0c;内核会返回一个文件描述符&#xff0c;读写文件也需要使用文件描述符来访问文件…

java需要会的工具_Java开发者必备的几款工具,一定要掌握!

原标题&#xff1a;Java开发者必备的几款工具&#xff0c;一定要掌握&#xff01;NotepadNotepad是用于编辑xml、脚本以及记笔记的最佳工具。这个工具的最好部分在于&#xff0c;你在Notepad上打开的任何一个文档&#xff0c;在关闭后都会有一个残留文档&#xff0c;它有助于在…

java的equals方法_Java LocalDateTime类| 带示例的equals()方法

java的equals方法LocalDateTime类equals()方法 (LocalDateTime Class equals() method) equals() method is available in java.time package. equals()方法在java.time包中可用。 equals() method is used to check whether this date-time and the given object are equal or…

portlet java_Java Portlet 规范概述

前言1、portlet是一种类似servlet的规范。2、servlet是web组件&#xff0c;portlet也是web组件。参考1、百度百科&#xff1a;portlethttp://baike.baidu.com/link?urlvMzVwpkf5WzOL23GLkgM4C5C7Sarqh1XXShS73L7k-MbGgM0ooZ4Dl2Efor3bb4tZmmLo6v-muG5UW7_CYMTUahttp://hintcnu…

Java LocalDate类| minusWeeks()方法与示例

LocalDate类minusWeeks()方法 (LocalDate Class minusWeeks() method) minusWeeks() method is available in java.time package. minusWeeks()方法在java.time包中可用。 minusWeeks() method is used to subtract the given weeks from this LocalDate and return the LocalD…

Android推荐的几本书

2019独角兽企业重金招聘Python工程师标准>>> 第一阶段 <<第一行代码Android>><<疯狂Android>>第二阶段 <<Android开发艺术探索>><<Android群英传>>Android源码 第三阶段 <<Android开发艺术探索>><&…