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 2 of 2

Thread: Need Help With Jtextfield inputs and Textfiles

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help With Jtextfield inputs and Textfiles

    i need help with storing inputs from JTextfield into a textfile (.txt)


    here is the code i have atm


    JButton btnNewButton = new JButton("Search By Author");
    btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {

    JFrame Frame1= new JFrame ("Search By Author");
    Frame1.setVisible(true);
    Frame1.setSize (500,200);
    //Name of the Author
    JTextField Name= new JTextField ("Enter Name:",30);
    Name.setBounds(30, 300, 150, 20);
    String Name1 = Name.getText();
    JPanel Panel= new JPanel();
    Frame1.getContentPane().add (Panel);
    Panel.add (Name);

    try {

    BufferedWriter Author =null;
    BufferedWriter Author2 = new BufferedWriter (new FileWriter ("./Author.txt"));
    Author2.write (Name.getText());
    }catch (IOException ioexception){
    System.out.print ("error");




    }}});
    it works so ar but it wont store the inputs into the textfile


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need Help With Jtextfield inputs and Textfiles

    it wont store the inputs into the textfile
    Does the code call the write() method? What is returned by the getText() method? Add a println to print out the String returned by getText() so you can see what is returned.
    Is the file closed after it is written to?
    Is the file created? What is in the file?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Can't get inputs to add up. Need help fast!!
    By Rick Sebastian in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 3rd, 2013, 02:20 PM
  2. [SOLVED] Scanner Requiring Two Inputs
    By Nate in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 17th, 2012, 05:46 PM
  3. Concatenating Inputs, need help please!
    By xdrechsler in forum File I/O & Other I/O Streams
    Replies: 17
    Last Post: August 19th, 2011, 01:02 PM
  4. How to store 10 inputs in an arraylist?
    By Bray92 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 20th, 2011, 10:22 PM
  5. Inputs not being applied.
    By Norflok669 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 15th, 2010, 01:25 AM