Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
May i know how to save the selected radio button value and text field value into a file?

What I have tried:

Java
private void SaveButActionPerformed(java.awt.event.ActionEvent evt) {                                        
        try{
        File f=new File("Customer detail.txt");
        String id = this.CusIDTxt.getText();
        String name=NameTxt.getText();
        String ic=ICNoTxt.getText();
        String ph=PhNoTxt.getText();
        String email=EmailAddTxt.getText();
        PrintWriter writer=new PrintWriter(new BufferedWriter(new FileWriter("Customer detail.txt",true)));
        writer.println(id);
        writer.println(name);
        writer.println(ic);
        writer.println(ph);
        writer.println(email);
        writer.close();
        JOptionPane1.showMessageDialog(this, "Register customer was successful");
        m.setVisible(true);
        this.setVisible(false);
        }
        catch(Exception e)
        {
            JOptionPane1.showMessageDialog(this,"All fields must be completed in order to register");
        }
    }
Posted
Updated 5-Apr-17 2:23am
v2
Comments
Jochen Arndt 5-Apr-17 8:17am    
You did not use f anywhere and have a file name without path.

What is happening when using 'PrintWriter writer=new PrintWriter(f);'?

Any exceptions?
If so, use 'e.printStackTrace();' to get additional information.

1 solution

In your code you have already saved text field values to a file (you saved the string returned by the getText method).
Usually a radio button represents the value of an allowed option, i.e. an item of an enumeration. You could save the integer value correspondig to the choosen item.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900