我正在尝试使用
请参考下面的代码片段,我想知道编译器在
我运行这段代码后的输出结果是:
但是当我以调试模式运行时,我得到了以下输出:
DataOupPutStream.write()
方法写入大于256的值。当我尝试使用DataInputStream.read()
读取相同的值时,它会返回0。因此,我使用了DataOutputStream.writeInt()
和DataInputStream.readInt()
方法来写入和检索大于256的值,并且运行良好。请参考下面的代码片段,我想知道编译器在
while
语句中的in.readInt()
执行什么操作。FileOutputStream fout = new FileOutputStream("T.txt");
BufferedOutputStream buffOut = new BufferedOutputStream(fout);
DataOutputStream out = new DataOutputStream(fout);
Integer output = 0;
out.writeInt(257);
out.writeInt(2);
out.writeInt(2123);
out.writeInt(223);
out.writeInt(2132);
out.close();
FileInputStream fin = new FileInputStream("T.txt");
DataInputStream in = new DataInputStream(fin);
while ((output = in.readInt()) > 0) {
System.out.println(output);
}
我运行这段代码后的输出结果是:
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at compress.DataIOStream.main(DataIOStream.java:34)
257
2
2123
223
2132
但是当我以调试模式运行时,我得到了以下输出:
2123
223
2132
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at compress.DataIOStream.main(DataIOStream.java:34)