i want program that reads the information from the file items.dat, and then creates another file named availableItems.dat containing the information (barcode, quantity, price) of only the available items (having quantity more than 0) followed by the expected income from selling all those items. The expected income can be measured as the sum of quantity*price for all items ... i did that but there is EOFException Exception i dont know why ?
info in file is recorded as follows:
77777 5 6.7 .. .. to 6 items
my code is :
import java.io.*;
class items{
public static void main(String[] args) throws IOException{
File f=new File("items.dat");
FileInputStream ff=new FileInputStream(f);
DataInputStream df=new DataInputStream(ff);
int[] barcod=new int[6];
int[] quan=new int[6];
double[] price=new double[6];
int i=0;
try{
while (i<barcod.length)
{
barcod[i]=df.readInt();
quan[i]=df.readInt();
price[i]=df.readDouble();
i++;
}
File f2=new File("availableItems.dat");
FileOutputStream ff2=new FileOutputStream(f2);
DataOutputStream dou=new DataOutputStream(ff2);
int s=0;
double sumquan=0;
double sumpri=0;
while (s<6)
{
if (quan[s]!=0)
{
dou.writeInt(barcod[s]);
dou.writeInt(quan[s]);
dou.writeDouble(price[s]);
sumpri+=price[s];
sumquan+=quan[s];
}
s++;
}
dou.writeDouble(sumpri*sumquan);
}
catch(EOFException e){
System.out.println(e);
}
finally{
df.close();
}
}
}