By way of an example I have a txt file that contains a list of dogs, one on each line of the file and then "**" on the last line. I then have the following code to load this into an ArrayList
to use in a JComboBox
.
This way I can simply add another line in the text box to add another dog.
My example code is as follows
public class test{
static String temp;
public static void main(String[] args) {
List<String> picklistDogs = new ArrayList<String>();
File picklistFile = new File (filePath);
try {
BufferedReader loadPickList = new BufferedReader (new FileReader(picklistFile));
while(true) {
temp = loadPickList.readLine();
if (temp != "**") {
picklistDogs.add(temp);
} else {
break;
}
}
loadPickList.close();
}
catch(FileNotFoundException e){
System.out.println("file not found");
}
catch(IOException e){
System.out.println("file io error");
}
} // END of main
} // END of class test
My problem seams to be that the if
statement never triggers the break
to exit the while
loop.
Any solutions would be appreciated.