Java.io.ByteArrayOutputStream.write() 方法
描述
java.io.ByteArrayOutputStream.write(int b) 方法将指定的字节写入此流。
声明
以下是 java.io.ByteArrayOutputStream.write(int b) 方法的声明 −
public void write(int b)
参数
b − 指定字节为0-255范围内的整数
返回值
此方法不返回任何值。
异常
NA
示例
下面的例子展示了 java.io.ByteArrayOutputStream.write(int b) 方法的使用。
package com.tutorialspoint;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class ByteArrayOutputStreamDemo {
public static void main(String[] args) throws IOException {
String str = "";
ByteArrayOutputStream baos = null;
try {
// create new ByteArrayOutputStream
baos = new ByteArrayOutputStream();
// write byte array to the output stream
baos.write(55);
// converts the byte to the default charset value
str = baos.toString();
// prints the string
System.out.println(str);
} catch(Exception e) {
// if I/O error occurs
e.printStackTrace();
} finally {
if(baos!=null)
baos.close();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
7

