Solved

Java search string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 46
Non-recursive backtracking, using a stack 1 96
couple of eclipse 5 16
varialbe initialization 11 30
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now