Link to home
Start Free TrialLog in
Avatar of darenceang
darenceang

asked on

Java search string

Hi!
I have a text file with username and password.
They are in the format username:password

When the user enters a new username to create, i would like to do a search in this text file to see if such a username has been taken up.
If it has taken up, to return a boolean true;
Please advice.

Cheers!
Darence

This is currently what have.
Please advice.

Boolean check = false;
FileInputStream fstream = new FileInputStream("test.txt");
DataInputStream checkUserName = new DataInputStream(fstream);
                              
while (checkUserName.available() !=0){
System.out.println (checkUserName.readLine());
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html

Why would it matter if just the username were taken? You need to check the name/password *pairs*
Avatar of darenceang
darenceang

ASKER

If the username is taken, then the username will not be created.
The system is like a user/password creation.

So if i enter an option to create user : darenceang

The system will check this txt file to see if darenceang has been registered before.
Else the system will prompt him for a password and then save it into the file as username:password.

I m stuck at the checking of username ( string ) from the inputstream.

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)