Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: write & read/load to/from file

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default write & read/load to/from file

    Hello, I need to write some objects to a file, then when I 'read' them back to the program, they have to be exactly the same, they have to be the same kind of objects, with the same name and everything, I have tried several different approches, but it all fails, the objects are 'accounts' for a bank (run over rmi)

        	AccountServer KAC= new AccountServer("Jane");
        	AccountServer JAC = new AccountServer("John");
     
        	Naming.rebind("Jane",KAC);	
        	KAC.setName("Jane");
        	KAC.setNumber(1234);
        	KAC.setBalance(600);
     
        	Naming.rebind("John",JAC);
        	JAC.setName("John");
        	JAC.setNumber(2345);
        	JAC.setBalance(50);

    The important thing here is the 'Naming.rebind' is has to become "Jane"/"John" or whatever the name is, becouse the bank client finds the account using 'Naming'
    Any thoughts? I am loosing my mind here


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,386
    Thanks
    49
    Thanked 2,208 Times in 2,181 Posts

    Default Re: write & read/load to/from file

    I have tried several different approches, but it all fails
    Can you post the code you have written to do this and explain what the problem with it is?

    Your coding does not follow standard java coding conventions: first letter of a classname should be uppercase, first letter of variable should be lowercase. What is Naming? classname of variable

    Also posted at: http://www.java-forums.org/new-java/...load-file.html
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: write & read/load to/from file

    Quote Originally Posted by Norm View Post
    Can you post the code you have written to do this and explain what the problem with it is?

    Your coding does not follow standard java coding conventions: first letter of a classname should be uppercase, first letter of variable should be lowercase. What is Naming? classname of variable

    Also posted at: write & read/load to/from file
    I have explaind the best I can on that place

  4. #4
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: write & read/load to/from file

    If your intention is to save the state of the object and read it again then serialization is the best way to do it. Save it using serialization and read it back by de-serializing

Similar Threads

  1. read & write object in object file
    By amirsarem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 8th, 2013, 11:35 AM
  2. Read and write file in Java
    By waiheng1986 in forum File Input/Output Tutorials
    Replies: 1
    Last Post: March 18th, 2012, 11:54 AM
  3. Java I/O File code; how to read/write file
    By ryu2le in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 18th, 2011, 05:51 PM
  4. Program to read & write the Employee Records
    By arvindk.vij in forum Member Introductions
    Replies: 1
    Last Post: February 11th, 2011, 12:19 AM
  5. Program to read & write the Employee Records
    By arvindk.vij in forum Java Theory & Questions
    Replies: 1
    Last Post: February 11th, 2011, 12:19 AM