Solved

Java search string

Posted on 2006-10-25
4
208 Views
Last Modified: 2010-03-31
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());
0
Comment
Question by:darenceang
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17801723
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*
0
 
LVL 4

Author Comment

by:darenceang
ID: 17801740
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!
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 20 total points
ID: 17801765
Place

boolean userFound = false;

before the code at that link i posted then replace the loop code with

     while ((str = in.readLine()) != null && !userFound) {
            userFound = str.startsWith(username);
     }


.............

     return userFound;

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17801817
:-)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 122
Java exception bubble up 2 24
How to convert from xls to xlsx using java 7 95
Java basic valueOf question 1 35
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question