Results 1 to 3 of 3
  1. #1
    Goodwine's Avatar
    Goodwine is offline Member
    Join Date
    Nov 2008
    Location
    Mexico
    Posts
    14
    Rep Power
    0

    Default Writing Data or Objects?

    Let's see, well I got a problem
    I have a program that saves objects with user data, however i think this is not the best idea because if the class changed then the object will not work and there will be crappy stuff around

    So i think it is better to write Data instead of Objects, my next problem is...
    how do I read data again to an object?

    Like I want to add "Name, Address, Birthday, Account, Password"
    then i need
    out.writeUTF(name);
    out.writeUTF(address);
    out.writeUTF(bday);
    out.writeUTF(acc);
    out.writeUTF(pass);

    but supposing i make a registry of 100 or 1000, lets say p people
    how do i read the data of say the person number n? (say, n=834)

    Supossing the user 834 changes his password, how am I supposed to save the changes on the file?
    Last edited by Goodwine; 11-26-2008 at 12:29 AM. Reason: Typo
    Si vis pasem para bellum
    -Vagecio

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Default

    I have found readLine() to be the only effective solution, one day I will go to writing binary which can be read in with DataInputStream, but for now I just do ( instinctively )

    String buffer = datafile.readLine();

    if(buffer != null)
    {
    .....

    which works if you get the right java.io filetype...
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Goodwine's Avatar
    Goodwine is offline Member
    Join Date
    Nov 2008
    Location
    Mexico
    Posts
    14
    Rep Power
    0

    Default

    Ok, I guess.
    I thought that perhaps i should write the acc first then the password, so when i look for the acc i save it, then i look for the password if it doesnt match, returns false on either case, if it does, it returns true and a new object is created or something similar

    But, how do i save changes when the user does something?
    Si vis pasem para bellum
    -Vagecio

Similar Threads

  1. Reading data from Micrsoft excel and writing to notepad
    By abhishek.jain in forum New To Java
    Replies: 4
    Last Post: 01-29-2009, 08:12 AM
  2. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 04:10 PM
  3. Replies: 0
    Last Post: 10-31-2008, 02:13 PM
  4. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:52 AM
  5. how many objects ?
    By kevinsong in forum Advanced Java
    Replies: 16
    Last Post: 07-16-2008, 05:59 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
  •