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");
String userNames = userTextField.getText();
FileInputStream fstream = new FileInputStream(destFile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader existingUsers = new BufferedReader(new InputStreamReader(in));
while((strLine = existingUsers.readLine()) != null)
boolean exists = userNames.equals(strLine);
if (exists == true)
JOptionPane.showMessageDialog(null, "User name already exists !! \n Please choose another username");
BufferedWriter out = new BufferedWriter(new FileWriter(destFile, true));
catch (IOException e)
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?