Results 1 to 2 of 2
  1. #1
    lectri is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default Problem when reading files

    Hi all!

    Im new in programming and I'm having a problem with a work I have to do, and I really need someone to tell me what I'm doing wrong.

    To sum up, what I have to do is to simulate a login system, so I created a class which has that funcionality, the 'login' method.

    By reading a file with Buffered reader, I have to enter with keyboard a code and a password, and then It has to check if they match (there are 2 codes and 2 passwords, each code associated to a password)

    The file is something like this (not this actually)

    code1:
    9872
    password:
    perfsf
    code2:
    0078
    password:
    uuylk

    Taking in count that I cant change anything in the file, how could I do it?

    What ive done is, by using 4 variables (passw, code, passwfile, codefile, 2 of them are filled by keyboard) I'd like to compare passw and code with passwfile and codefile, which are filled by reading the file.

    Well, the problem is that I dont know how to assign to passwfile and to codefile the right line of the file in order to compare them with passw and code.

    Any help?

    (Sorry for my bad english, it's not my native language)

    Thank you.

    If you need part of my code I'll post it.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: Problem when reading files

    You will need to take input from the User, which you could do with the Scanner class. You then need to read a text file and check if what the user entered matches any password/username combination - You can also do that with the Scanner class.

    You can read more about it here:
    Scanner (Java 2 Platform SE 5.0)
    Scanning (The Java™ Tutorials > Essential Classes > Basic I/O)

Similar Threads

  1. Reading files
    By ptuckley in forum New To Java
    Replies: 7
    Last Post: 08-16-2011, 03:18 AM
  2. problem reading a files lines
    By j187 in forum New To Java
    Replies: 1
    Last Post: 12-17-2010, 01:43 AM
  3. Bug Reading txt files
    By MHardeman25 in forum New To Java
    Replies: 4
    Last Post: 08-13-2010, 11:03 PM
  4. Reading .bin files
    By spatel14 in forum New To Java
    Replies: 3
    Last Post: 06-22-2010, 05:39 PM
  5. Replies: 5
    Last Post: 08-21-2009, 12:03 PM

Posting Permissions

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