DataOutputStream.write(int b)方法示例
DataOutputStream
的DataOutputStream.write(int b)
方法具有以下语法。
public void write(int b) throws IOException
示例
在下面的代码中展示了如何使用DataOutputStream.write(int b)
方法。
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
int[] buf = { 65, 66, 67, 68, 69, 70, 71 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
for (int i : buf) {
dos.write(i);
}
dos.flush();// At: W W w .Y IIb a i。c O M
for (byte b : baos.toByteArray()) {
char c = (char) b;
System.out.print(c);
}
}
}
上面的代码生成以下结果。
ABCDEFG