i have a file from which i have to read and compute the total value of all items,i dont know what methodto use to read arrays
i tried DataInputStream(object).readInt(quantity[]); but it says it is wrong
can any one help me in reading from the file and computing the total value of all the items
the code is as follows
import java.util.*;
import java.io.*;
public class FiveProducts
{
static DataInputStream dis = new DataInputStream(System.in);
static StringTokenizer st;
public static void main(String args[])throws IOException
{
//create file where data to be stored
FileOutputStream fos = new FileOutputStream("fivepro.dat");
DataOutputStream dos = new DataOutputStream(fos);
//declare variables
int prodcode[]= new int[4];
double cost[]= new double[4];
int quantity[]=new int[4];
DataInputStream din = new DataInputStream(new FileInputStream("fivepro.dat"));
//reading from console
for(int i=0;i<4;i++)
{
System.out.println("enter code number for items = " + i);
st = new StringTokenizer(dis.readLine());
prodcode[i] = Integer.parseInt(st.nextToken());
dos.writeInt(prodcode[i]); //write to file
}
for(int j=0;j<4;j++)
{
System.out.println("enter cost of item = " + j);
st = new StringTokenizer(dis.readLine());
cost[j]= new Double(st.nextToken()).doubleValue();
dos.writeDouble(cost[j]); // write to file
}
for(int k=0;k<4;k++)
{
System.out.println("enter quantity of item = " + k);
st = new StringTokenizer(dis.readLine());
quantity[k] = Integer.parseInt(st.nextToken());
dos.writeInt(quantity[k]); // write to file
}
dos.close();
din.close();
}
}