hi guys, i need some help to solve a problem which i am encountering. basically i have designed a very simple login screen, the username is created and saved in a textfile. i need to first make sure that no similar username is there so i have to check the username is this exists in the text file. the code i have written is as follows.
File destFile = new File("C:\\DATAX\\DESTINATIONS\\STAGING\\usernames. txt");
try
{
String userNames = userTextField.getText();
System.out.println(userNames);
FileInputStream fstream = new FileInputStream(destFile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader existingUsers = new BufferedReader(new InputStreamReader(in));
String strLine;
// System.out.println(strLine);
while((strLine = existingUsers.readLine()) != null)
{
System.out.println(strLine);
boolean exists = userNames.equals(strLine);
if (exists == true)
{
JOptionPane.showMessageDialog(null, "User name already exists !! \n Please choose another username");
break;
}
else
{
BufferedWriter out = new BufferedWriter(new FileWriter(destFile, true));
userTextField.write(out);
out.newLine();
out.flush();
out.close();
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
JOptionPane.showMessageDialog(null,"Username successfully created");
}
the code is creating a username but is not checking if the username exists. can someone help me pls?
tks
