I am doing a project and i want to have a text file with usernames and passwords like
and i will put a login form so the user will type the username and password and through the text file, the program will check the information and then login. So i want some help how to write the code to check this information when the user type them.
You will be able to hard-code the file name and location. I'd suggest that you load the file only once for each session - the first time someone logs in - and that you read the data into a map/dictionary collection with the key being whatever "public" information you have. I would write file loading method using a Scanner object because of the datatype checking and flexibility of the methods exposed by the class. If this is a new user, and the data meets your requirements, you would write to the collection in memory, then write the collection to disk to save the file each time a new registration is completed or as the session ends. It might be helpful - if you are up for it - to use the NIO routines and open a channel which would help synchronize the data in memory and in your file stored on more permanent storage.