Java DataOutputStream size()方法及示例
DataOutputStream类的size()方法 (DataOutputStream Class size() method)
size() method is available in java.io package.
size()方法在java.io包中可用。
size() method is used to return the size of this stream or in other words, we can say it returns the value of the variable counter that contains written bytes.
size()方法用于返回此流的大小,换句话说,可以说它返回包含已写入字节的变量计数器的值。
size() 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.
size()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
size() method does not throw an exception at the time of returning size.
返回size时, size()方法不会引发异常。
Syntax:
句法:
public final int size();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is int, it returns the last value of the variable counter.
方法的返回类型为int ,它返回变量计数器的最后一个值。
Example:
例:
// Java program to demonstrate the example
// of int size() method of DataOutputStream
import java.io.*;
public class SizeOfDOS {public static void main(String[] args) throws IOException {InputStream is_stm = null;
DataInputStream dis_stm = null;
FileOutputStream fos_stm = null;
DataOutputStream dos_stm = null;
byte[] b_arr = {12,
20,
45,
98,
75,
69,
30,
58,
47,
61,
83,
55
};
try {// Instantiate FileInputStream,
// DataInputStream, FileOutputStream
// and DataOutputStream
fos_stm = new FileOutputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
dos_stm = new DataOutputStream(fos_stm);
is_stm = new FileInputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
dis_stm = new DataInputStream(is_stm);
// Loop to write each byte till end
for (byte val: b_arr) {// By using write() method isto
// write a byte value to the
// DataOutputStream dos_stm
dos_stm.write(val);
}
// Loop To Read Available Data till end
while (dis_stm.available() > 0) {// By using read() method isto read
// byte from dis_stm
int in = dis_stm.read();
System.out.println("dis_stm.read(): " + in );
}
System.out.println();
// By using size() method isto return
// size of this stream
int size = dos_stm.size();
System.out.println("dos_stm.size(): " + size);
} catch (Exception ex) {System.out.println(ex.toString());
} finally {// To free system resources linked
// with these streams
if (is_stm != null)
is_stm.close();
if (dis_stm != null)
dis_stm.close();
if (dos_stm != null)
dos_stm.close();
if (fos_stm != null)
fos_stm.close();
}
}
}
Output
输出量
dis_stm.read(): 12
dis_stm.read(): 20
dis_stm.read(): 45
dis_stm.read(): 98
dis_stm.read(): 75
dis_stm.read(): 69
dis_stm.read(): 30
dis_stm.read(): 58
dis_stm.read(): 47
dis_stm.read(): 61
dis_stm.read(): 83
dis_stm.read(): 55dos_stm.size(): 12
翻译自: https://www.includehelp.com/java/dataoutputstream-size-method-with-example.aspx
Java DataOutputStream size()方法及示例相关推荐
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- Java 中array.size()_Java ArrayDeque size()方法与示例
ArrayDeque类size()方法size()方法在java.lang包中可用. size()方法用于返回存储在此双端队列中的大小(元素数). size()方法是一个非静态方法,只能通过类对象访问 ...
- Java List.size()方法:返回列表中元素的个数(亲测)
Java 集合类中的 List.size() 方法以 int 形式返回列表中元素的个数. 语法: size() 返回列表中元素的个数.如果列表中元素的个数超过 2 147 483 647,则返回 2 ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- 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对象表示的进程完成其终止为止. 当 ...
最新文章
- C4D运动图形基本训练学习教程
- jquery实现图片懒加载
- 什么是 CMS - Content Management System
- Python 测试驱动开发(四)测试及重构的目的(上)
- 第7章[7.22] Ext JS类的继承与混合
- CDH页面中Oozie的调度告警邮箱设置
- 最详尽的 JS 原型与原型链终极详解(1)(2)(3)===转载
- 组态王通过串口服务器通讯smart200_实例讲解通过代码调试串口通讯的方法
- 关闭极域电子教室学生端的各种方法
- 关系抽取论文阅读笔记
- (转)女人,别忘了经营自己!(同事亲身经历)
- HTML的学习-2|HTML 标签(上)
- 房地产行业分销渠道管理系统:促进渠道商内外沟通,提升成交效率
- 视频行人重识别系统(UI界面,Python源码,可下载)
- Logism · 汉字字库存储芯片扩展 实验
- Elasticsearch+X-pack和Java Transport方式连接
- 从DockerHub中拉取、查看、保存、导入、删除,nginx镜像
- C3P0(数据库连接池)详解
- 《嵌入式 – GD32开发实战指南》第17章 看门狗
- 如何评估数据库的安全风险?
热门文章
- c语言里字符串和字符串字面量,string literals(字符串字面量)
- java cas原理_Java并发之原子变量及CAS算法-上篇
- 四因素三水平正交表_做论文要用正交表?我打包送给你
- golang定时任务的使用
- HTTP1.1新增了五种请求方法:OPTIONS、PUT、PATCH、DELETE、TRACE 、 CONNECT
- Redis详解(三)
- [译] 想帮助用户做决定?你的APP可以这样设计!
- Android推荐的几本书
- poj 3254 状压dp
- 用dw(dreamweaver)开发asp.net,连接数据库时出现“http错误500,服务器内部错误”的解决方法...