?
Solved

From textboxes to text file

Posted on 2003-03-18
8
Medium Priority
?
162 Views
Last Modified: 2010-03-31
Hi

Just want help in printing values from textboxes into a text file. Its a simple programme in which a user enters details about themselves ie.Name and when they click the enter button, the information entered into the textboxes is inputted into a text file.
If there is anyone out there who would be able to code this it would be greatly appreciated.

Thanks in advance.
0
Comment
Question by:rebel_vb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Accepted Solution

by:
mitchweb1 earned 200 total points
ID: 8162666
Here are the parts that should help you a bit with your problem, just fit them in the right place in your code, you need to import the javax.swing to get the option panel to work. hope this helps

import javax.swing.*;
//TO GET INFORMATION
String <VARIABLE> = JOptionPane.showInputDialog(null, "Enter Integer");



//TO WRITE TO FILE

try {
                    BufferedWriter buffer = new BufferedWriter(new FileWriter(<YOUR FILENAME>, true));
                    buffer.newLine();
                    buffer.write(<VARIABLE NAME>);
                    buffer.close();
                } catch (IOException e) {
                }
                    System.exit(0);
          }
};
0
 

Expert Comment

by:mitchweb1
ID: 8162683
forgot to mention, the way that code is written means it will append to a file of your choice, on a new line... presuming thats what you want it to do?
0
 
LVL 1

Assisted Solution

by:FaithNoMore
FaithNoMore earned 200 total points
ID: 8162931
If the information from the text boxes make a object you can use writeObject();  I am currently at work, so my syntax may be a little off.

You may have problems reading in the objects after they have been saved (ie. ClassNotFoundException) which can be fixed with a little work.



import java.io.*;

public class Person implements Serializable
{
    String name;
    int age;
    // ..etc

   public Person(String name, int age)
   {
     this.name = name;
     this.age = age;
   
   }


//Method takes in a Person object and writes it to
//the PersonFile.txt.  If the file doesnt exsist it
//will be created.
  static void SavePerson( Person person )
   {
      File file = new File("personFile.txt");
      ObjectOutputStream out;
      try{
      out = new ObjectOutputStream(
                  new FileOutputStream(file));
      writeObject(person);
      out.close()
      }catch(IOException err){
          err.printStackTrace();
      }
   }

}

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:FaithNoMore
ID: 8163324
Also, to get the info from the text fieldds use:

TextField Name = new TextField();
String name;
TextField Age = new TextField();
int age;

name = Name.getText().trim();
double temp = new Double(Age.getText().trim());
age = temp.intValue();  //I think this will work?

Person p = new Person(name, age);
Person.SavePerson(p);

0
 

Author Comment

by:rebel_vb
ID: 8168288
Just like to thank ye all for the help. Much appreciated. After posting 2 more questions, again any help is appreciated. Thanks again.
0
 

Expert Comment

by:CleanupPing
ID: 9058614
rebel_vb:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9727120
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between mitchweb1 and FaithNoMore

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question