Howdy,
I'm trying to write a method which needs to read a text file formatted:
userasswordroduct1roduct2
I have it working only if there's one line in the text file, more than one, it crashes. Here's my code, any clue to what I need to do to get it working?
private boolean validateUser(String id, String password) {
String record = null;
int TokCounter=0;
int TotLen = 0;
int LookLen = 0;
boolean matching = false;
String LookFor = null;
try {
FileReader fr = new FileReader("C:/password.txt"
BufferedReader br = new BufferedReader(fr);
while ((record = br.readLine()) != null) {
LookFor= id + ":" + password + ":";
record = new String();
record = br.readLine();
if (record.startsWith (LookFor))
TotLen = record.length();
LookLen = LookFor.length();
record = record.substring(LookLen, TotLen);
StringTokenizer tok = new StringTokenizer(record, ":"
while (tok.hasMoreTokens()){
String token = tok.nextToken();
TokCounter = TokCounter + 1;
if (TokCounter==1)
CompanyName= token;
if (TokCounter==2)
Prod1= token;
if (TokCounter==3)
Prod2= token;
matching = true;
}
} catch (IOException e) {
matching = false;
}
return matching;
}
Thanks for any help.
I'm trying to write a method which needs to read a text file formatted:
userasswordroduct1roduct2
I have it working only if there's one line in the text file, more than one, it crashes. Here's my code, any clue to what I need to do to get it working?
private boolean validateUser(String id, String password) {
String record = null;
int TokCounter=0;
int TotLen = 0;
int LookLen = 0;
boolean matching = false;
String LookFor = null;
try {
FileReader fr = new FileReader("C:/password.txt"
BufferedReader br = new BufferedReader(fr);
while ((record = br.readLine()) != null) {
LookFor= id + ":" + password + ":";
record = new String();
record = br.readLine();
if (record.startsWith (LookFor))
TotLen = record.length();
LookLen = LookFor.length();
record = record.substring(LookLen, TotLen);
StringTokenizer tok = new StringTokenizer(record, ":"
while (tok.hasMoreTokens()){
String token = tok.nextToken();
TokCounter = TokCounter + 1;
if (TokCounter==1)
CompanyName= token;
if (TokCounter==2)
Prod1= token;
if (TokCounter==3)
Prod2= token;
matching = true;
}
} catch (IOException e) {
matching = false;
}
return matching;
}
Thanks for any help.