Results 1 to 11 of 11
  1. #1
    jadaleus is offline Member
    Join Date
    Oct 2008
    Posts
    12
    Rep Power
    0

    Default Saving To A New Line Using A Text File

    can anyone tell me why my text is not saving to new line, it just appends at the end of the last text.

    here's part of my code:

    if(event.getSource() == signupButton) {

    try {

    outFile1 = new PrintWriter ( new FileWriter("register.txt",true));
    outFile1.print(usernameField.getText()+" ");
    outFile1.print(password.getText() +"* ");
    outFile1.flush();
    outFile1.close();
    JOptionPane.showMessageDialog(null,"Data have been Saved");
    usernameField.setText("");
    password.setText("");

    }

  2. #2
    andy_man's Avatar
    andy_man is offline Member
    Join Date
    Oct 2008
    Location
    Yerevan
    Posts
    14
    Rep Power
    0

    Default

    mmm, sorry but your question is very odd...

    so which text does append at the end of which other text?
    TEAM = Together Everyone Achieves More :)

  3. #3
    jadaleus is offline Member
    Join Date
    Oct 2008
    Posts
    12
    Rep Power
    0

    Default

    lets say I have a textfield, and I am saving to a text file, the text from the textfield will not save to a newline in the textfile but append at the end of the existing text.

    hope thats clear

  4. #4
    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

    After adding a text line to the file, add a new line there as well.

    Can you show your code which can see what exactly going on your code. That above part not make a clear sense.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default

    There's a difference between print(...) and println(...)

    db

  6. #6
    andy_man's Avatar
    andy_man is offline Member
    Join Date
    Oct 2008
    Location
    Yerevan
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by jadaleus View Post
    Java Code:
    can anyone tell me why my text is not saving to new line, it just appends at the end of the last text.
    
    here's part of my code:
    
    if(event.getSource() == signupButton) {
    					
    try {
    				
    [B]outFile1 = new PrintWriter ( new FileWriter("register.txt",true));
    outFile1.print(usernameField.getText()+" ");
    outFile1.print(password.getText() +"* ");
    outFile1.flush();
    outFile1.close();[/B]JOptionPane.showMessageDialog(null,"Data have been Saved");			
    usernameField.setText("");
    password.setText("");
    				
    	}
    If this is the code which is writing to the file, besides of println, you can also just write something like:

    Java Code:
    outFile1.print(usernameField.getText()+" " + "\n");
    This will add the new line at the end of the line.
    TEAM = Together Everyone Achieves More :)

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default

    Quote Originally Posted by andy_man View Post
    If this is the code which is writing to the file, besides of println, you can also just write something like:

    Java Code:
    outFile1.print(usernameField.getText()+" " + "\n");
    This will add the new line at the end of the line.
    Now why would one want to do that? And why the space between the end of the text and the newline? And even if that had been necessary, why two concatenations where one would suffice?

    I'm sorry, but your 'suggestion' is exceedingly poor code.

    db

  8. #8
    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

    Why don't you workout with Darryl.Burkes' suggestion. As he says you have done very poor thing in your code.

  9. #9
    jadaleus is offline Member
    Join Date
    Oct 2008
    Posts
    12
    Rep Power
    0

    Default Thank You

    Thanks for nothing, the code does exactly what my code did, what I have noticed in this forum is that everyone seems to not know much about java and its suppose to be ADVANCE and comments on why was my text and new line is separated how sad db COME ON. This is the last of me using this forum.

  10. #10
    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

    No one wants to comments on you as well lol. What db is suggest you is the way you have to take. Reason is that comment on you is he(me too) cannot is any attempt you have take on in your code.

    It's upto you. If you think members in our forum doesn't have much knowledge on Java, and you feel that no one here help you in the future, just left our community. Anyone cannot ask to stay here. Good luck!

  11. #11
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by jadaleus View Post
    This is the last of me using this forum.
    Your question was not clear. From what folks guessed you were asking, it does not belong in the Advanced section.

    There are quite a few folks here who are knowledgeable about Java, but we can't read your mind.

    More importantly, with your lack of communication skills, and lack of social skills, I sure will not miss you.

Similar Threads

  1. saving to a new line a text
    By jadaleus in forum Advanced Java
    Replies: 1
    Last Post: 10-20-2008, 06:10 PM
  2. Saving to a Text File
    By jadaleus in forum Advanced Java
    Replies: 2
    Last Post: 10-17-2008, 06:50 PM
  3. Saving data in an XML file
    By Thez in forum New To Java
    Replies: 1
    Last Post: 12-08-2007, 09:24 PM
  4. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 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
  •