Results 1 to 10 of 10
  1. #1
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default How to Modify,Delete data in File Txt???

    I have some record in File *.txt like this:

    Write and Read i use FileWriter+BufferedWriter & FileReader+BufferedReader

    AccountNumber AccoutnName AccountBalance
    1 aaa 100
    2 bbb 200
    3 ccc 300

    Example:
    how can i modify the AccoutnName "bbb" to "ccc" or "ddd" ???
    how can i delete a second record???

    Write and Read i use FileWriter+BufferedWriter & FileReader+BufferedReader

    I really need help!
    Thanks!

  2. #2
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    Store the modified records in tem.txt file ..
    delete the original file ..
    and rename the temp file to original name ..

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    In such a case what I'm doing is read the file store them in a collection. Then it's easy to do any manipulation on it. Finally write all data to a file.

  4. #4
    nanaji is offline Member
    Join Date
    May 2008
    Posts
    31
    Rep Power
    0

    Default

    If he is having a 500000 and above records, then the above ideas are not efficient right? If that is the case, what you guys suggest.I mean is there any Persistent Collection Object to handle this kind of situation.

  5. #5
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Smile Hmmmmm.

    Quote Originally Posted by nanaji View Post
    If he is having a 500000 and above records, then the above ideas are not efficient right? If that is the case, what you guys suggest.I mean is there any Persistent Collection Object to handle this kind of situation.


    i think this was one of the reason for which data base was invented.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by DevzAbhi View Post
    i think this was one of the reason for which data base was invented.
    100%. That's the best choice.

  7. #7
    khajalid is offline Member
    Join Date
    Sep 2008
    Posts
    31
    Rep Power
    0

    Default

    I think you should use separator between each field.Read data line by line and store according to fields using substring(). Then compares data to be modified with substring of that field.You must use separate string for each field.
    You should open file in append mode.If you don't find matching string add as it is to file otherwise ad the modified data

  8. #8
    nanaji is offline Member
    Join Date
    May 2008
    Posts
    31
    Rep Power
    0

    Default

    I m more concern about memory, not with programming. First of all , if you have 500000 records, don't have the memory to load into list. What i mean is, Serializable list .

    Regards
    Nanaji

  9. #9
    satu is offline Member
    Join Date
    Aug 2008
    Posts
    12
    Rep Power
    0

    Default

    use StringBuffer, StringTokenizer instead of all because it is fast and full featured for this kind of work.

  10. #10
    nanaji is offline Member
    Join Date
    May 2008
    Posts
    31
    Rep Power
    0

    Default

    String buffer stored into memory. Idea should be serialized collection.

Similar Threads

  1. [SOLVED] Delete Current line from file
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 04-06-2012, 08:00 AM
  2. Delete From .txt file
    By Sarinam in forum New To Java
    Replies: 86
    Last Post: 06-28-2008, 10:17 AM
  3. Replies: 0
    Last Post: 04-05-2008, 10:13 AM
  4. problem when I try to delete a file
    By tommy in forum Advanced Java
    Replies: 2
    Last Post: 07-31-2007, 02:44 PM
  5. How to delete a file
    By Alpha in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 08:11 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
  •