将数据以格式化读出,并在显示器上显示出来:
//将数据读出
DataInputStream in = new DataInputStream(new FileInputStream("order.txt"));
double prices;
int num;
String buffer desc;
try{
//当文本被全部读出以后会抛出EOFxception异常,中断循环
while(true){
price=in.readDouble(); //读出价格
in.readChar();//跳出tab
num=in.readInt();//读出数目
in.readChar();
char ch;
desc = new StringBuffer();
while(((ch=in.readChar())!='\n') desc.append(ch);//读取字符串
System.out.println(""价格"+ price+" 数目"+num+" 名称"+desc);
}
}catch(EOFException e){
e.printkStrace();
}