java file readline returns null
I am trying to create a booking system in Java, however every time I run
the program the while loop (shown below) skips straight to the end as
though the line read was null
//hardcoded file path - needs to be changed when program moved
String fileName =
"C:\\Users\\BOO\\Desktop\\SystemsSoftwareBookingsystem\\FilmData.txt";
String line = null;
int readInt = 0;
float readFloat = 0;
int item_counter = 0;
try
{
BufferedReader bufferedReaderF = new BufferedReader(new
FileReader(new File(fileName)));
while ((line = bufferedReaderF.readLine()) != null)
{
Film tmpFilm = new Film();
switch (item_counter)
{
case 0:
{
line = bufferedReaderF.readLine();
tmpFilm.name = line;
item_counter++;
}
case 1:
{
readInt = bufferedReaderF.read();
tmpFilm.seatsTotal = readInt;
item_counter++;
}
case 2:
{
readInt = bufferedReaderF.read();
tmpFilm.seatsAvailable = readInt;
item_counter++;
}
case 3:
{
readInt = bufferedReaderF.read();
tmpFilm.price = readFloat;
item_counter++;
}
case 4:
{
readInt = bufferedReaderF.read();
tmpFilm.showingTime = readFloat;
item_counter++;
}
case 5:
{
readInt = bufferedReaderF.read();
tmpFilm.day = readInt;
item_counter++;
}
case 6:
{
readInt = bufferedReaderF.read();
tmpFilm.month = readInt;
item_counter++;
}
case 7:
{
readInt = bufferedReaderF.read();
tmpFilm.year = readInt;
item_counter = 0;
}
}
line = bufferedReaderF.readLine();
server.filmList.add(tmpFilm);
}
bufferedReaderF.close();
} catch (FileNotFoundException ex)
{
System.out.println("Unable to open file '" + fileName + "'");
} catch (IOException ex)
{
System.out.println("Error reading file '" + fileName + "'");
}
}
}`
any ideas / help would be greatly appreciated
EDIT added rest of the code in the while loop as requested
No comments:
Post a Comment