ObjectInputStream类readLong()方法 (ObjectInputStream Class readLong() method)

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

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

  • readLong() method is used to read 8 bytes (i.e. 64 bit) of long value from this ObjectInputStream stream.

    readLong()方法用于从此ObjectInputStream流中读取8个字节(即64位)的长值。

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

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

  • readLong() method may throw an exception at the time of reading long.

    readLong()方法在读取较长时间时可能会引发异常。

    • IOException: This exception may throw when getting any input/output error while performing.IOException :在执行过程中遇到任何输入/输出错误时,可能引发此异常。
    • EOFException: This exception may throw when this stream has reached its end of the file.EOFException :当此流到达文件末尾时,可能引发此异常。

Syntax:

句法:

    public long readLong();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is long, it returns the 8 bytes long value read.

该方法的返回类型为long ,它返回读取的8个字节的long值。

Example:

例:

// Java program to demonstrate the example
// of long readLong() method of ObjectInputStream
import java.io.*;
public class ReadLongOfOIS {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 writeLong() method is to write
// long to the obj_out_stm stream
obj_out_stm.writeLong(5411489332534l);
obj_out_stm.writeLong(234773224114l);
obj_out_stm.flush();
while (obj_in_stm.available() > 0) {// By using readLong() method is to read
//  long from the obj_in_stm
long val = (int) obj_in_stm.readLong();
System.out.println("obj_in_stm.readLong(): " + val);
}
// By using close() method is to
// close all the streams
file_in_stm.close();
file_out_stm.close();
obj_in_stm.close();
obj_out_stm.close();
}
}

Output

输出量

obj_in_stm.readLong(): -169460426
obj_in_stm.readLong(): -1449977166

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

Java ObjectInputStream readLong()方法(带示例)相关推荐

  1. inputstream 关闭 java,Java ObjectInputStream close()方法与示例

    ObjectInputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此ObjectInputStream并释放与此流链接的所有系统资源. cl ...

  2. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  3. java getmonth_Java LocalDateTime类| 带示例的getMonth()方法

    java getmonth LocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method i ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  6. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  7. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  8. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  9. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

最新文章

  1. Rocksdb 的一些参数调优策略
  2. php common errors
  3. Linux环境下进入MySQL环境报权限问题:Access denied for user 'root@localhost' (using password:YSE)...
  4. delphi xls 线程_锐龙9 5950X怒超近6GHz!关键是16核心32线程全开-锐龙,锐龙9 5950X,超频 ——快科技(驱动之家旗下媒体)-...
  5. java中的abstract和interface差异
  6. Criteria查询之分页显示数据
  7. HDU 2001 计算两点间的距离
  8. 11、MySQL算术运算符
  9. 学习笔记-------两阶段提交 2PC
  10. php前后端分离两个域名访问,Laravel 5.4前后台分离,通过不同的二级域名访问方法...
  11. BZOJ3235 [Ahoi2013]好方的蛇 【单调栈 + dp】
  12. java 沙盒模拟支付_网站对接paypal支付接口记录
  13. 重读模电教材一_童诗白、华成英
  14. php jmail 乱码,Jmail发送邮件与带附件乱码解决办法分享
  15. 行业分析-全球与中国船用废气解决方案市场现状及未来发展趋势
  16. 新的一年,红包走起!
  17. P3287 [SCOI2014]方伯伯的玉米田
  18. OpenCV中Viz模块的安装(VS2015)
  19. 基于安卓平台的远程医疗APP设计
  20. 电子商务安全欺诈预防市场现状研究分析-

热门文章

  1. 当面试官问你如何进行性能优化时,你该这么回答(一)
  2. 课时39.细线表格(理解)
  3. upload file more than 4MB
  4. 【区块链Go语言实现】Part 1:区块链基本原型
  5. perl6正则 4: before / after 代码断言: ?{} / !{}
  6. Javascript学习之函数(function)
  7. 独家:Havok 发布新的 AI 中间件
  8. 如何做好一名软件实施人员 (转载)
  9. java setsession_Java Session.setServerAliveInterval方法代码示例
  10. linux伙伴系统算法,Linux伙伴系统(三)--分配