CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    15

    Question Help with text file

    I am doing a project and i want to have a text file with usernames and passwords like

    john 12345
    nick 56780
    taki 9087

    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.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help with text file

    If you post up your code and explain exactly where you are having a problem, we will help you fix it.

    I hear and I forget; I see and I remember; I do and I understand...
    Confucius
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Oct 2006
    Posts
    15

    Re: Help with text file

    i have no idea what i have to do, i know only how to read data from a text file. like this
    private static String readFileAsString(String filePath) throws java.io.IOException
    {
    StringBuffer fileData = new StringBuffer(1000);
    BufferedReader reader = new BufferedReader(
    new FileReader(filePath));
    char[] buf = new char[1024];
    int numRead=0;
    while((numRead=reader.read(buf)) != -1){
    fileData.append(buf, 0, numRead);

    }
    reader.close();
    return fileData.toString();
    }

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help with text file

    It looks like you need to figure out how your program is going to work before you write any code. Just reading the whole file into single String isn't going to be very helpful. You want to be able to compare the login details with each set of details in the file, which means reading it line by line, because each line contains a set of login details.

    We can't teach Java here, and we can't teach you how to design an application - these are things you must figure out for yourself. If you work out the steps you need to accomplish the task you have been given, and then try to translate them into Java code, we can help you if you get stuck. But first you have to work out exactly what needs to be done to solve the problem (hint: pretend you are the computer - how would you do the task by hand? break it down into simple steps).

    Good teaching is more a giving of the right questions than a giving of the right answers...
    J. Albers
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured