我有一个库存程序,它不会加载我的结果

时间:2013-12-02 23:44:52

标签: java

我有这个库存程序,但我无法获取要加载的信息。我对编程很陌生。我认为它在load方法中是for循环。或者它可能是myinven [I] = new Item(iID);在加载方法中。

public class Inventory {
    int count = 0;
    int max = 4;
    Item[] myinven = new Item[max];
    Scanner input = new Scanner(System.in);

    public void save() {
        PrintWriter outputStream = null;
        try {
            outputStream = new PrintWriter(new FileOutputStream("Inventory.txt"));
        } catch (FileNotFoundException e) {
            System.out.println("Error opening the file");
        }
        for (int I = 0; I <= count - 1; I++)
            if (outputStream != null) {
                outputStream.println(myinven[I].getID());
                outputStream.println(myinven[I].getname());
                outputStream.println(myinven[I].getdescription());
                outputStream.println(myinven[I].getonhand());
                outputStream.println(myinven[I].getunitprice());
                outputStream.close();
            }
    }

    public void load() {
        Scanner inputStream = null;
        try {
            inputStream = new Scanner(new FileInputStream("Inventory.txt"));
        } catch (FileNotFoundException e) {
            System.out.println("The File was not found");
        }

        for (int I = 0; I <= count - 1; I++) {
            if (inputStream != null) {
                while (inputStream.hasNext()) {
                    myinven[I] = new Item(inputStream.nextInt());
                    myinven[I].setname(inputStream.nextLine());
                    myinven[I].setdescription(inputStream.nextLine());
                    myinven[I].setonhand(inputStream.nextInt());
                    myinven[I].setunitprice(inputStream.nextDouble());
                    inputStream.close();
                }
            }
        }
    }
}

0 个答案:

没有答案