Results 1 to 8 of 8
  1. #1
    Thug heart is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default reading data from text file .. help plz

    Hi every body ,,


    Happy Valentine Day


    I'm new member and I really I have no clue in JAVA. I have download BlueJ and the JDK ,,,


    I'm trying to do the following :


    I want to Implement the following problem in Java.


    I have two files , employe.txt and transaction_file.txt

    The master employe.txt file has the following layout:
    Employee_ID_number, Last_Name, First_Name, Salary, Number_Dependents, Department,

    The transaction_file.txt has the following layout:

    1657, D
    3982, A, Fred, Lincon, 56534, 1, Shipping
    0192, U, cooper
    0190, A, abdul, Tilli, 89855, 0, Accounting

    A = Add a record
    U = Update a record
    D = Delete a record

    I want to make a progame which can read the files. no user input. The I can just pass through the employee file and one pass through the transaction file in a staggered stair step fashion. In other words I don't want take the first transaction record and search all the way through the employee list, then take the second transaction record and search all through the employee list again, and so on. I hope you got my idea ...

    The program should generate the following transaction log.

    1657 D record not deleted, record does not exist
    3982 A record not added, record already exists
    0192 U record Updated.
    0190 A record Added



    I really spent 48 hours trying to do it but I could not


    Could you help me please ??!!
    Attached Files Attached Files

  2. #2
    ramsrocker is offline Member
    Join Date
    Feb 2009
    Posts
    48
    Rep Power
    0

    Default

    man you gotta walk before you can run.. this would take me awhile and ive been programming for a month. start with some tutorials.

  3. #3
    Thug heart is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    Thank you for being optimistic !! loooooooooooooooooool

  4. #4
    jurka is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    If it's not your home assignment why not to use some lightweight database ? So you can make two tables and join them, which would be much more effective.

    I recommend to use Hsqldb or SQLite.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Because given the nature of the restrictions on how to solve this, it is most obvious that it in fact is his homework assignment and as such, the original poster should be the one to do it.

    to the original poster, we are great at answering specific questions or helping find a subtle bug in a piece of posted code, but unfortunately don't do very well at helping questions of your type which are known as "homework dumps": were folks drop the complete assignment here and claim that they don't know where to start. Please realize that we're all volunteers with lives, jobs, families and time constraints and all, and what you really need is a way to jump-start your Java education through intense study and tutoring.

    I strongly suggest that you get up with your tutor and start reviewing your material so you can catch up with the rest of your class. Also study the basic Sun Java tutorials that you can find here:

    Trail: Learning the Java Language (The Java™ Tutorials)

    Good luck

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Drunk up the stairs?

    ...and one pass through the transaction file in a staggered stair step fashion
    staggered stair step fashoin? Never heard of it... could you please explain?

    Thanks,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    Thug heart is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    hi guys


    I don't want you to solve this or to give me the code ! , all what I want just give a hint about it


    I'm trying to do it by myself and since that I can not find any tourer , so just if you guys give me any idea , any guideline ,,, , I will be so happy with that




    Thank you anyway

  8. #8
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Here's a good way to do it I found on the internet.
    Java Code:
    private String readFileAsString(String filePath) throws IOException {
            StringBuilder fileData = new StringBuilder(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);
            }
            fileData.trimToSize();
            reader.close();
            return fileData.toString();
        }
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

Similar Threads

  1. Reading Integers from a text file
    By tress in forum New To Java
    Replies: 6
    Last Post: 02-26-2011, 06:45 PM
  2. Problem with reading text from a .txt file
    By Gigi in forum New To Java
    Replies: 40
    Last Post: 01-22-2009, 04:22 AM
  3. Reading two text file and sum them up
    By matt_well in forum New To Java
    Replies: 36
    Last Post: 07-22-2008, 03:55 AM
  4. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 12:38 AM
  5. Reading Data from a file
    By ramachandran in forum New To Java
    Replies: 2
    Last Post: 10-24-2007, 08:22 AM

Posting Permissions

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