Append a single text file on button click through jTextField [a complete form]

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.

Dear Norm. Yes i did it but where I have to implement this code in my programme and the code is written below...

package org.kodejava.example.io;

import java.io.*;

public class AppendFileExample

{

public static void main(String[] args)

{

File file = new File("user.txt");

try

{

FileWriter writer = new FileWriter(file, true);

writer.write("username=kodejava;password=secret"

+ System.getProperty("line.separator"));

writer.flush();

writer.close();

} catch (IOException e)

{

e.printStackTrace();

}

}

}

--- Update ---

Can you explain what the program does when it executes? (YES)
Does it create a new file? (YES)
Does it replace an existing file?(YES)
What data i written to the file?(YES)
Is the correct data written to the file?(YES)

I would like to implement this code in my programme to append the file like in this code appending the file is work properly but how can i arrange this code in my programme code as above mention in first post.

If you now know how to create a file or open a file and append records to the file, you need to copy the logic to your other program.
Open the file in append mode before you want to write to it,
write to it when you have the data to be written and
close the file when you are done writing to the file.

Can you find those places in the code to do each of those things?

Note: The code should NOT have all statements starting in the first column.

Several ways:
Use an ArrayList to hold the Strings
Use an array to hold the Strings
Define a custom class that can contain multiple Strings
Put all the Strings in one String with a special character separating them.