Results 1 to 9 of 9
  1. #1
    billdef is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default update binary file from text file

    i want to learn how i can update a dbs file from a text file,for example:

    dbs.file
    name1 tel1 e-mail1
    name2 tel2 e-mail2
    ---------------------
    text file
    name1 tel1 e-mail3 e-mail4
    name2 tel2 e-mail2 tel 1112222 phone 777777
    -------------------------
    update dbs
    name1 tel1 e-mail1 e-mail3 e-mail4
    name2 tel2 e-mail2 tel 1112222 phone 777777
    can anyone help??????

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

    Default

    What you mean by dbs file? In the title you are talking about binary file, but in the file you are talking about contain some text. Am I correct?

  3. #3
    billdef is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default

    no it's no text,it's a binary file, it has records no characters!!!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Check your terminology. Records can be built from characters.
    A record is a sequence of bytes(could be chars) with some relationship.
    Usually we use the term binary for data that can't be entered from the keyboard.
    And text is what can be entered from a keyboard.

    What is a "dbs" file? How does it relate to the text file? The examples you posted both appear to be files that contained text.

  5. #5
    billdef is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default

    i think you haven't work a lot with files....of course i talk abou t bytestreams....and in a binary file there are records.writnig and reading is made with objects...serialization/desirialization....i don't understand where my terminology is wrong

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    i think you haven't work a lot with files.
    That's an interesting comment. Take a look at my profile.

    in a binary file there are records
    That does NOT mean that there are NOT records in other types of files. If you have a special meaning for the generic word record, please enclose it in quotes or add an adjective to show what specific type of record you are working with.

    in a binary file ... writing and reading is made with objects
    That's one way. There are others. What is an image file? It contains binary data and has nothing to do with objects and serialization.

  7. #7
    billdef is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default

    ok,i write an example how is the database:in the example i have already input some records,you give a record id and you can see the corresponding data.
    the record members are:name-10 chars,tel(int),e-mail(10chars)
    ----------
    RandomAccessFile infile=new RandomAccessFile(f,"rw");
    long id,pos;
    byte nam[]=new byte[20];
    do
    {System.out.println("record number (0:exit)==>");
    id=object.console_long();
    if (id==0) break;
    pos=(id-1)*24;
    infile.seek(pos);
    for int j=0;j<10;j++)
    nam[j]=infile.readByte();
    tel=infile.readInt();
    for (int i=0;i<10;i++)
    System.out.println((char)nam[i]);
    System.out.println(tel);
    }
    while(true);
    infile.close();
    )
    )
    my question is how i can update this file from a text file

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    how i can update this file from a text file
    You have two files, one with binary records, the other with text records.
    The "binary" file has records of length of 24 bytes with the following fields:
    name - 10 bytes(char)
    tel# - 4 bytes(int)
    email - 10 bytes(char)

    What is the layout of the records in the text file?

    Your example showed that the changed binary file would have different length fields than the input file. If the email field is only 10 bytes long, how can you update it to be a longer field? Do the "fields" have delimiters or length fields to say how long they are?
    And what about the "phone" data? That seems to be an new set of fields for the record.

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default

    What is this binary file anyway?
    It's not the data file for some other system (db, or whatever) is it?

Similar Threads

  1. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  2. Replies: 2
    Last Post: 05-11-2009, 10:07 AM
  3. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  4. Converting a text file int binary
    By sruthi_2009 in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 03:09 PM
  5. Update Text File
    By yuminstall in forum New To Java
    Replies: 8
    Last Post: 01-09-2009, 03:02 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
  •