实际代码用于将值编码为数组中每个对象的属性。但是,它仅使用最后一行的信息来填充每个值。
Scanner data = new Scanner(new DataInputStream(new FileInputStream("trucklist.txt")));
for (int i = 0; i < maxSize; i++)
{ for(;data.hasNext();)
{
t[i].setVin(data.next());
t[i].setMake(data.next());
t[i].setModel(data.next());
t[i].setColor(data.next());
t[i].setYear(data.next());
t[i].setBaySize(data.nextDouble());
t[i].setCabSize(data.nextDouble());
addElement(t[i]);
}
}
哪里trucklist.txt
是:
12x4578w Ford F-150 Black 2005 17.2 6.8
12x4589w Ford F-150 Blue 2005 17.2 6.8
12x4587f Ford F-250 Black 2007 60.8 9.5
12x4589z Ford F-150x White 2005 15.4 10.2
数组元素仅由每个元素的最后一组属性填充。任何帮助将不胜感激。