0

nextLine()テキストファイルの読み取りに問題があります。以前、この種のテキスト ファイルを使用.next()してみましたが、正常に動作しました。

2
3333
CookingRange
50 450.00 850.00
4444
CircularSaw
150 45.00 125.00

nextLine()文字列の間にスペースがあっても、行を読み取るために使用してファイルから入力を読み取りたいと思います。

2
3333
Cooking Range
50 450.00 850.00
4444
Circular Saw
150 45.00 125.00

そして、私はこの種のエラーを抱えています

http://i.stack.imgur.com/CHfGp.png

基本的に私のコードは次のようになります

public class console {
    public static void main(String[] args) throws IOException {
        Scanner inFile = new Scanner(new FileReader("items.in"));

        //products

        int itemCount = inFile.nextInt();
        Vector<item> pList = new Vector<item>();

        double totalProfitForItem = 0.0;
        double totalSellingvalueForItem =  0.0;
        double totalAmount = 0.0;
        int totalStock = 0;

        String itemID;
        String itemName;
        int pcsInStore;
        double manufPrice;
        double sellingPrice;
        int j;

        for (int i = 0; i < itemCount; i++) {

            itemID = inFile.nextLine();
            itemName = inFile.nextLine();
            pcsInStore = inFile.nextInt();
            manufPrice = inFile.nextDouble();
            sellingPrice = inFile.nextDouble();

            item s = new item(itemID, itemName, pcsInStore, manufPrice, sellingPrice, totalSellingvalueForItem, totalProfitForItem);
            pList.addElement(s);

            totalAmount += totalSellingvalueForItem;
            totalStock += pcsInStore;
        }


        for( j = 0; j < pList.size(); j++) {
            System.out.printf("%5s %5s  %5.2f %.2f \n", pList.elementAt(j).getItemID(), pList.elementAt(j).getItemName(), pList.elementAt(j).totsell(), pList.elementAt(j).totprof());
            totalSellingvalueForItem = pList.elementAt(j).totsell();
            totalAmount += totalSellingvalueForItem ;
        }

        System.out.println("\n");
        System.out.println("Total Amount of Inventory: " + totalAmount +"0");
        System.out.println("Number of Items in the Store: " + totalStock);    
    }    
}
4

2 に答える 2