Java.io.DataOutputStream.writeByte() 方法 Java.io.DataOutputStream.writeBoolean() 方法 Java.io.DataOutputStream.writeBytes() 方法 Java.io.DataOutputStream.writeByte() 方法 package com.codingdict; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; public class DataOutputStreamDemo { public static void main(String[] args) throws IOException { ByteArrayOutputStream baos = null; DataOutputStream dos = null; byte[] buf = {12, 15, 30, 40, 5, 7}; try { // create byte array output stream baos = new ByteArrayOutputStream(); // create data output stream dos = new DataOutputStream(baos); // write to the output stream from the buffer for(byte b: buf) { dos.writeByte(b); } // flushes bytes to underlying output stream dos.flush(); // for each byte in the buffer content for(byte b:baos.toByteArray()) { // print character System.out.print(b + " "); } } catch(Exception e) { // if any error occurs e.printStackTrace(); } finally { // releases all system resources from the streams if(baos!=null) baos.close(); if(dos!=null) dos.close(); } } } Java.io.DataOutputStream.writeBoolean() 方法 Java.io.DataOutputStream.writeBytes() 方法