目录

void write(int b)

描述 (Description)

java.io.ByteArrayOutputStream.write(int b)方法将指定的字节写入此流。

声明 (Declaration)

以下是java.io.ByteArrayOutputStream.write(int b)方法的声明 -

public void write(int b)

参数 (Parameters)

b - 指定的字节为整数,范围为0-255

返回值 (Return Value)

此方法不返回任何值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.io.ByteArrayOutputStream.write(int b)方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018