Java ByteArrayOutputStream size()方法与示例

ByteArrayOutputStream类size()方法 (ByteArrayOutputStream Class size() method)

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

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

  • size() method is used to return the current size of the buffer exists.

    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 the size.

    在返回大小时, size()方法不会引发异常。

Syntax:

句法:

    public int size();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is int, it returns the current size of the buffer exists in this stream.

方法的返回类型为int ,它返回此流中存在的缓冲区的当前大小。

Example:

例:

// Java program to demonstrate the example 
// of int size() method of ByteArrayInputStream
import java.io.*;
public class SizeOfBAOS {
public static void main(String[] args) throws Exception {
byte[] b_arr = {
97,
98,
99,
100
};
ByteArrayOutputStream BAOS = null;
try {
// Instantiates ByteArrayOutputStream
BAOS = new ByteArrayOutputStream();
// By using write() method is to
// write b_arr to the BAOS
BAOS.write(b_arr);
// By using toString() method is 
// to represent the BAOS as a string
System.out.println("BAOS.toString(): " + BAOS.toString());
// By using size() method is
// to return the size of the
// stream
int s_size = BAOS.size();
System.out.println("BAOS.size(): " + s_size);
} catch (Exception ex) {
System.out.println(ex.toString());
} finally {
if (BAOS != null)
BAOS.close();
}
}
}

Output

输出量

BAOS.toString(): abcd
BAOS.size(): 4

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

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

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

相关文章

Oracle备份文件名获取系统时间的做法(windows)

在对数据库进行备份时,用数据泵的方法,需要执行一段代码: --建目录 create directory dir as d:\bak;--给用户授权使用目录 grant read,write on directory dir to scott;--在cmd中输入以下代码 expdp scott/tigerXE directorydir dumpfileab…

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

java getmonthLocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method is available in java.time package. getMonth()方法在java.time包中可用。 getMonth() method is used to get the field value month-of-year based on the enum Mon…

阿里最喜欢问的多线程顺序打印的5种解法!

Keeper导读大家在换工作面试中,除了一些常规算法题,还会遇到各种需要手写的题目,所以打算总结出来,给大家个参考。全文 2929 字,剩下的是代码,P6 及以下阅读只需要 8 分钟,高 P 请直接关闭第一篇…

CSS入门

CSS入门1_CSS概要1.1_CSS引入方式2_CSS选择器3_字体样式3.1_字体属性3.2_字体类型:font-family3.3_字体大小:font-size3.4_字体粗细:font-weight3.5_字体颜色:color3.6_总结4_文本样式4.1_文本样式属性4.2_首行缩进:te…

Oracle笔记:数据库启动的三个阶段

数据库的启动可分为三个阶段:1、startup nomount -- 启动实例,不加载数据库 nomount:在这一阶段,只需要读取initSID.ora文件,启动数据库实例,创建后台进程。在initSID.ora文件中,可以定位…

Java LocalDate类| lengthOfYear()方法和示例

LocalDate类lengthOfYear()方法 (LocalDate Class lengthOfYear() method) lengthOfYear() method is available in java.time package. lengthOfYear()方法在java.time包中可用。 lengthOfYear() method is used to get the length of the year represented by this LocalDate…

23张图!万字详解「链表」,从小白到大佬!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)链表和数组是数据类型中两个重要又常用的基础数据类型。数组是连续存储在内存中的数据结构,因此它的优势是可以通…

何为“秒传”

写在前面 最近一直在弄文件传输的组件,在讨论组里面,有同事提到“秒传”的功能。在目前的通信软件中也有网盘的功能,就从网上搜了一下,这里对“秒传”的实现思路做一下总结,在之后会写一个小的demo实现一下。没有其他&…

JavaScript入门

JavaScript入门1_语法基础1.1_变量1.2_数据类型1.3_运算符1.4_类型转换1.5_注释跟c一样2_流程控制语句3_函数3.1_没有返回值的函数3.2_有返回值的函数4_对象4.1_对象简介4.2_字符串对象4.3_数组对象4.4_时间对象4.5_数学对象简介5_DOM基础5.1_DOM是什么5.2_节点类型5.3_获取元素…

oracle 序列的概念与使用步骤

转载自:http://www.worlduc.com/blog2012.aspx?bid20342458 一、概念 1、 序列: 是oacle提供的用于产生一系列唯一数字的数据库对象。主要用于提供主键值。 2、 创建序列: 创建序列的语法 CREATE SEQUENCE sequence //创建序列名称 [INCREMENT BY n]…

数组转List的3种方法和使用对比!

作者 | 大脑补丁来源 | blog.csdn.net/x541211190/article/details/79597236前言:本文介绍Java中数组转为List三种情况的优劣对比,以及应用场景的对比,以及程序员常犯的类型转换错误原因解析。一.最常见方式(未必最佳)…

java 根据类名示例化类_Java即时类| getEpochSecond()方法与示例

java 根据类名示例化类即时类getEpochSecond()方法 (Instant Class getEpochSecond() method) getEpochSecond() method is available in java.time package. getEpochSecond()方法在java.time包中可用。 getEpochSecond() method is used to get the number of seconds from t…

oracle10g备份导入

2019独角兽企业重金招聘Python工程师标准>>> //导出 exp test/testgdsoft filed:\gd.dmp //删用户 drop user wkwx cascade; //用PLSQL创建数据数据库 create user hzjzjn identified by hzjzjn default tablespace BDP_DATABD; grant CREATE USER,DROP USER,ALTE…

VisualSVNServer的使用

VisualSVNServer的使用1_服务端初识1.1_创建新仓库1.2_创建用户并分配权限1_服务端初识 1.1_创建新仓库 右击Repository,点击create 点击下一步 输入仓库名 右击空白处,点击新建,点击project structure 输入工程名 1.2_创建用户并分…

安利一个IDEA骚操作:一键生成方法的序列图

在平时的学习/工作中,我们会经常面临如下场景:阅读别人的代码阅读框架源码阅读自己很久之前写的代码。千万不要觉得工作就是单纯写代码,实际工作中,你会发现你的大部分时间实际都花在了阅读和理解已有代码上。为了能够更快更清晰地…

overflow滚动条属性

做网页的时候,因为网页内容的长短不一样,并且滚动条的策略默认是自动,所以网页的滚动条根据内容一会有一会没有。我的网页做的是居中的,所以滚动条在有和没有的时候,会影响网页内容的位置,这样感觉不太好&a…

c#中textbox属性_C#.Net中带有示例的TextBox.Multiline属性

c#中textbox属性Here we are demonstrating use of Multiline property of the TextBox Control. 在这里,我们演示了TextBox控件的Multiline属性的使用。 Multiline property contains two values: 多行属性包含两个值: True: We can enter text in mo…

MATLAB新手教程

MATLAB新手教程 1.MATLAB的基本知识 1-1、基本运算与函数 在MATLAB下进行基本数学运算,仅仅需将运算式直接打入提示号(>>)之後,并按入Enter键就可以。比如: >> (5*21.3-0.8)*10/25 an…

嗯,查询滑动窗口最大值的这4种方法不错....

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)本文已收录至 Github《小白学算法》系列:https://github.com/vipstone/algorithm这是一道比较基础的算法题&…

Oracle创建视图、通过视图创建表

创建视图: create or replace view v$_tst23 as select e.ename,d.dname from emp e left join dept d on e.deptno d.deptno;创建表: --如果表已存在,先删除 --drop table tst23a; --创建表格(通过视图) --可以在whe…