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()方法用于返回緩沖區(qū)當(dāng)前存在的大小。
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()方法是一種非靜態(tài)方法,只能通過類對(duì)象訪問,如果嘗試使用類名稱訪問該方法,則會(huì)收到錯(cuò)誤消息。
size() method does not throw an exception at the time of returning the size.
在返回大小時(shí), size()方法不會(huì)引發(fā)異常。
Syntax:
句法:
public int size();Parameter(s):
參數(shù):
It does not accept any parameter.
它不接受任何參數(shù)。
Return value:
返回值:
The return type of the method is int, it returns the current size of the buffer exists in this stream.
方法的返回類型為int ,它返回此流中存在的緩沖區(qū)的當(dāng)前大小。
Example:
例:
// Java program to demonstrate the example // of int size() method of ByteArrayInputStreamimport 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 ByteArrayOutputStreamBAOS = new ByteArrayOutputStream();// By using write() method is to// write b_arr to the BAOSBAOS.write(b_arr);// By using toString() method is // to represent the BAOS as a stringSystem.out.println("BAOS.toString(): " + BAOS.toString());// By using size() method is// to return the size of the// streamint 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
總結(jié)
以上是生活随笔為你收集整理的Java ByteArrayOutputStream size()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA Opencv在图片上添加中文
- 下一篇: 公司新来的小可爱,竟然把内存搞崩了!