Solved

Java search string

Posted on 2006-10-25
4
207 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 72
session migration servlets 2 42
Groovy problem when using SOAPUI : DispatchException occurred 7 58
How to convert String matching to regex in java 4 48
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

790 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