假设我的输入文件包含:
3 4 5 6 7 8
9
10
我想运行一个while循环并读取整数,这样在每次循环迭代后,我将分别得到3、4、5、6、7、8和10。
在C/C++中,这非常简单,但在Java中却不是...
我尝试了这段代码:
try {
DataInputStream out2 = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
int i=out2.read();
while(i!=-1){
System.out.println(i);
i=out2.readInt();
}
} catch (IOException ex) {
}
我得到的是:
51
540287029
540418080
538982176
151599117
171511050
218762506
825232650
我该如何在Java中从这个文件中读取整数?