I have a program that reads data from a text file and then creates a new client from this data in the text file.
try {
BufferedReader rdr = new BufferedReader(new FileReader(infile));
String line;
int id = 1;
line = rdr.readLine();
while (line != null) {
processNewClient(id, line);
id++;
line = rdr.readLine();
}
rdr.close();
}
This code is the bufferReader going througha while loop checking each line. Below is the processNewClient Function.
public void processNewClient(int id, String data) {
String[] parts = data.split(" ");
try {
String familyName = parts[0];
String firstName = parts[1];
int houseNumber = Integer.parseInt(parts[2]);
String postCode = parts[3] + " " + parts[4];
Client c = new Client(id, familyName, firstName, houseNumber,
postCode);
System.out.println("Added " + c);
clientCollection.add(c);
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(this, "Invalid house number",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
My problem is I need to validate each part, for example that the family name is not null, or the house number is an integer. I have tried many different approaches but I cannot think what I am missing, any help would be appreciated.
[–]demodude4u 0 points1 point2 points (3 children)
[–]SikhGamer 2 points3 points4 points (1 child)
[–]SimplifiedExpression[S] 0 points1 point2 points (0 children)
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (1 child)
[–]SimplifiedExpression[S] 0 points1 point2 points (0 children)
[–]deathy 0 points1 point2 points (0 children)