我正在使用这种方法
static void readFile()
{
try
{
FileInputStream fstream = new FileInputStream( "Insurances.txt" );
BufferedReader br = new BufferedReader( new InputStreamReader( fstream ) );
String strLine;
String [] array;
while ( ( strLine = br.readLine() ) != null )
{
array = strLine.split( "," );
pword++;
int type = Integer.parseInt(array[0]);
int tm = Integer.parseInt(array[1]);
int year = Integer.parseInt(array[2]);
int month = Integer.parseInt(array[3]);
int day = Integer.parseInt(array[4]);
int pass = Integer.parseInt(array[5]);
double tc = 0;
if ( type==2 )
{
String man = array[6];
String mod = array[7];
int cc = Integer.parseInt(array[8]);
String lp = array[9];
String ex = array [10];
boolean extra;
if ( ex.equals("true") )
{
extra = true;
}
else
{
extra = false;
}
insurances[insur] = new CarInsurance( pword, type, tm, year, month, day, pass, tc, man, mod, cc, lp, extra );
tc = insurances[insur].calculateCost( pass, a, insur );
insurances[insur].setCost( tc );
insur++;
}
else
{
insurances[insur] = new LifeInsurance( pword, type, tm, year, month, day, pass, tc );
tc = insurances[insur].calculateCost( pass, a, insur );
insurances[insur].setCost( tc );
insur++;
}
System.out.println("y");
}
inp.close();
}
catch ( Exception e )
{
e.getMessage();
}
}
从 txt 文件中读取一些信息并创建我的 LifeInsurance 类或我的 CarInsurance 的对象。我使用它的原因System.out.println("y");
是查看它是否完成了与我想要创建的对象一样多的循环。当我尝试运行我的程序时,我只得到 7 个循环(7 y's),但我需要 13 个。以下是我在 txt 文件中写的内容:
1,12,2013,6,1,1939
2,12,2008,1,10,1939,梅赛德斯,E200,2000,AEX32100,假
2,12,2009,1,11,1939,梅赛德斯,E200,2000,AEX32100,假
2,12,2009,2,10,1940,菲亚特,Punto,1400,BIO1245,假
2,12,2009,2,10,1940,Seat,Ibiza,1600,BIE3987,false
2,12,2010,1,10,1940,Seat,Ibiza,1600,BIE3987,false
2,12,2013,6,1,1941,奥迪,A4,1600,IXE1256,真
1,12,2008,1,2,1942
1,12,2009,1,2,1942
1,12,2010,1,2,1942
1,12,2011,1,2,1943
2,12,2010,7,23,1943,雷诺,Clio,1400,ZIO3890,true
2,12,2011,7,23,1943,雷诺,Clio,1400,ZIO3890,true
你能帮我吗,因为我找不到它没有完成所有 13 个循环的原因。先感谢您。