Hi. What to you mean by 'not working'? Remember
ItDoesntWorkIsUseless.
Post the file you are trying to read.
I launched your program with text file below and it worked:
However it kept looping when file was larger that 7 lines.
Unless you know that your file is exactly 7 lines long (and it will always be!), don't read data into fixed-length array of length 7.
Use a list instead.
And there is no need to call
br.ready(). You could just use
readLine method of
BufferedReader. It returns null when you reach end of file.
Also, there is no need to check if file exists.
FileReader constructor will throw an exception if it happens.
If you are using Java7 you could use try-with-resources.
Check out this code: