我在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);
}
}