Sorry for the long code. Here it loops through a text file with up to 5 lines and reads a random line. If the line it reads is null then it generates a random response. However when compiled with a test file of 2 lines it only has an output 2/5 of the time - when it reads from the text file. The other times it prints null. As you caqn see I have tried many ideas in the if statement but nothing seems to work.
int check_phrase = (int) (Math.random()*4);
//reads file lines until chosen line is found
try {
BufferedReader r = new BufferedReader(new FileReader(f));
boolean check =false;
int c = 0;
while(!check){
response = r.readLine();
c++;
//if the text file is too short then generate a response
if(response == "" || response == "\n" || response == null){
generateword();
check = true;
}else{
usedfile = true;
}
if(c>=check_phrase){
check = true;
}
}
}
catch (IOException e) {
generateword();
}