Hi all. I am very new to programing and don't understand what I am doing wrong. I believe it is because my var. "line" will always have a value, thus the while loop never terminates.
How do I fix this so that the program will output the reg. numbers?
------------------------------------------------------------------------------------------------------------------------------
import java.io.*; //import java.util.StringTokenizer; public class CarReg { public static void main (String []args) throws IOException { BufferedReader fr; fr = new BufferedReader (new FileReader("carreg.txt")); String line = fr.readLine(); int count = 0; String carArr[]; carArr = new String [50]; while (line !=null) { carArr[count] = fr.readLine(); count++; } for (int loop = 0; loop <=count ;loop++) { System.out.println ("Car Reg: " + carArr[loop]); } } }
------------------------------------------------------------------------------------------------------------------------------
This is the information in the text file called carreg.txt:
BMK123GP
HJD678GP
HAAI677NW
HJK676GP
JJK678NW
GGH898GP
HJK678GP
GHJ878GP
BMK123GP
JKO677NW
JAMBLIK6GP
KDK872NW
JFJ765GP
HDF809NW
DFG567GP
BMK123GP
JKO677NW
HJD678GP
JKO677NW
HJK676GP
DFG567GP
JKJ343NW
HJK678GP
GHJ878GP
YOYO55GP
SDF789NW
DFS678GP
HJD678GP
BMK123GP
HDF809NW
HJD678GP
JKO677NW
Some help would really be appreciated
Thanks,
bmaan.