Java ObjectOutputStream writeFloat()方法与示例

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

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

    在java.io包中提供了writeFloat()方法

  • writeFloat() method is used to write the given 4 bytes of a float value.

    writeFloat()方法用于写入给定的4个字节的浮点值。

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

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

  • writeFloat() method may throw an exception at the time of writing float.

    writeFloat()方法在编写float时可能会引发异常。

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

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

Syntax:

句法:

    public void writeFloat(float value);

Parameter(s):

参数:

  • float value – represents the float value to be written.

    浮点值 –表示要写入的浮点值。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of void writeFloat(float value) method of 
// ObjectOutputStream
import java.io.*;
public class WriteFloatOfOOS {
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 writeFloat() method is to
// write the float to the stream		
obj_out_stm.writeFloat(10.0f);
obj_out_stm.writeFloat(20.0f);
obj_out_stm.writeFloat(30.0f);
obj_out_stm.writeFloat(40.0f);
obj_out_stm.flush();
// By using readFloat() method is to 
// read the float 
for (int i = 0; i < 4; ++i) {
float f = obj_in_stm.readFloat();
System.out.println("obj_in_stm.readFloat(): " + f);
}
// 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.readFloat(): 10.0
obj_in_stm.readFloat(): 20.0
obj_in_stm.readFloat(): 30.0
obj_in_stm.readFloat(): 40.0
Stream Shutdown...

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

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

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

相关文章

python安全攻防---信息收集---whois查询

whois是用来查询域名的IP以及所有者信息的传输协议。简单地说&#xff0c;whois就是一个数据库&#xff0c;用来查询域名是否以及被注册&#xff0c;以及注册域名的详细信息&#xff08;如域名所有人、域名注册商等&#xff09;。 使用whois查询&#xff0c;首先通过pip安装py…

百度面试题:从输入url到显示网页,后台发生了什么?

参考http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/ http://www.cnblogs.com/wenanry/archive/2010/02/25/1673368.html 原文:http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/ 作为一个软件开发者&#xff0c;你一定会…

VS2005无法启动修复办法

c:\Program Files\Microsoft Visual Studio 8\Common7\IDE>devenv /ResetSkipPkgs 转载于:https://www.cnblogs.com/doc/archive/2008/10/10/1307887.html

Java——设计模式(工厂方法模式)

* A:工厂方法模式概述* 工厂方法模式中抽象工厂类负责定义创建对象的接口&#xff0c;具体对象的创建工作由继承抽象工厂的具体类实现。* 简单来说&#xff1a;先定义一个工厂&#xff0c;工厂里面有些方法&#xff0c;这些方法就是用来创建动物的&#xff0c;然后有很多子工…

python安全攻防---爬虫基础---get和post提交数据

get提交数据1 get提交的数据就附在提交给服务器的url之后&#xff0c;以&#xff1f;开头参数之间以&隔开&#xff0c;例如/admin/user/123456.aspx?name123&id123 案例&#xff1a;写个脚本&#xff0c;在sogou自动搜索周杰伦&#xff0c;并将搜索页面的数据获取 程…

JavaMail中解决中文附件名乱码的问题

网上有很多类似的解决方案&#xff0c;很多是使用 if ((fileName ! null) && (fileName.toLowerCase().indexOf("gb2312") ! -1)){ fileName MimeUtility.decodeText(fileName); } 来解决&#xff0c;但对应gbk编码的附件名&#xff0c;这里仍不能正确处…

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. write…

如何集中注意力(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…