【发布时间】:2020-10-24 04:28:58
【问题描述】:
为什么编译下面的代码会产生一个ASCII码值:GHI?我以为字节是数字数据类型?见以下代码:
import java.io.*;
public class PrintStreamDemo {
public static void main(String[] args) {
byte c[] = {70, 71, 72, 73, 74, 75, 76};
// create printstream object
PrintStream ps = new PrintStream(System.out);
// write bytes 1-3
ps.write(c, 1, 3);
// flush the stream
ps.flush();
}
}
【问题讨论】:
-
通过 PrintStream 发送字节,您将它们打印为 ASCII 字符。 71 是 G,72 是 H,73 是 I。
-
你必须使用 ByteArrayInputStream 来读取字节内容。