I want to add strings from a file to a StringBuilder so that I can display the information as one String. How come the line System.out.println(sb.toString()); isn't displaying in console? I cant tell if the code is working right, and it doesnt show any errors.
File Example:
LastName
FirstName
ID
Hometown
HomeState
Phone Number
String input = textFieldLastName.getText() is gathered from a JTextField
private String filename = "test.txt"
private static File file;
private static PrintWriter outputFile;
@SuppressWarnings("rawtypes")
private static JList list;
private static Scanner inputFile;
public void Read() throws IOException {
if(file == null || filename.equals("")) {
System.out.println("File not selected!");
}else{
inputFile = new Scanner(filename);
StringBuilder sb = new StringBuilder();
sb.delete(0, sb.length());
DefaultListModel listModel = new DefaultListModel();
while(inputFile.hasNext()){
// Read the next name
String ln = inputFile.nextLine();
String input = textFieldLastName.getText();
if(input.equalsIgnoreCase(ln)){
// Save friend information to variables
sb.append(ln);
for(int i = 0; i <=5; i++){
sb.append(", " + inputFile.nextLine());
}
listModel.addElement(sb.toString());
System.out.println(sb.toString());
}
}
list = new JList();
list.setModel(listModel);
}
}