need help!. how do you display the name of the person who just logged in from .txt file?, here is my login code
<pre>public void Masuk(){
try {
String lokasi = "D:/settings.txt";
String username = txtUser.getText();
String password = txtPass.getText();
FileReader fr = new FileReader(lokasi);
BufferedReader br = new BufferedReader(fr);
String line, user, pass;
boolean isLoginSuccess = false;
while ((line = br.readLine()) != null) {
user = line.split(" ")[1].toLowerCase();
pass = line.split(" ")[2].toLowerCase();
if (user.equals(username) && pass.equals(password)) {
isLoginSuccess = true;
this.dispose();
new Main_Menu(this, rootPaneCheckingEnabled).show();
break;
}
}
if (!isLoginSuccess) {
JOptionPane.showMessageDialog(null, "USERNAME/PASSWORD WRONG", "WARNING!!", JOptionPane.WARNING_MESSAGE);
}
fr.close();
}catch(Exception e){
e.printStackTrace();
}
}
and here is my jdialog form to display the name of the person who just logged in
public void Berhasil(){
String data = "D:/Settings.txt";
try {
FileReader fr = new FileReader(data);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine(),nama;
nama = line.split(" ")[0].toLowerCase();
String message = "Selamat datang "+ nama;
String text;
while ((line = br.readLine()) != null)
txtBerhasil.setText(""+message);
}
catch (FileNotFoundException fnfe) {
fnfe.getMessage();
}
catch (IOException ioe) {
ioe.getMessage();
}
}
and this is how my .txt file look like
Luthfi Luthfi Hehe
Luthfi Fitra Hehe
i supposed to display the first word only, because the first word is the name, and the second word is the username, and the third word is the password
What I have tried:
i already tried questioning at the stackoverflow but i dont get any big help
ps: sorry for my bad english