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

Thread: Write on File on what is on TextField

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

    Default Write on File on what is on TextField

    Hi just wanted to know a simple way of writing on a file whatever is written on the textfield after pressing a button. I would really appreciate any help on this one. thanks!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,094
    Thanks
    48
    Thanked 2,152 Times in 2,125 Posts

    Default Re: Write on File on what is on TextField

    See the PrintWriter class for writing text to a file.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    hawkeye01 (March 24th, 2013)

  4. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Write on File on what is on TextField

    I found this very simple application for the PrintWriter.

    // Demonstrate PrintWriter 
    import java.io.*; 
    public class PrintWriterDemo { 
    public static void main(String args[]) { 
    PrintWriter pw = new PrintWriter(System.out, true); 
    pw.println("This is a string"); 
    int i = -7; 
    pw.println(i); 
    double d = 4.5e-7; 
    pw.println(d); 
    } 
    }

    So I just set the file name on the PrintWriter, but how do I copy the string on the Jtextfield?

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,094
    Thanks
    48
    Thanked 2,152 Times in 2,125 Posts

    Default Re: Write on File on what is on TextField

    how do I copy the string on the Jtextfield?
    Read the API doc for the JTextfield class. It has a method for getting the text it contains as a String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. help with GUI .. read file and write file
    By kernal in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 14th, 2012, 10:38 AM
  2. Write something to the next available line in a file
    By frozen java in forum Java Theory & Questions
    Replies: 2
    Last Post: December 7th, 2011, 01:09 AM
  3. Java I/O File code; how to read/write file
    By ryu2le in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 18th, 2011, 05:51 PM
  4. Cannot Write to the file
    By isuru in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: July 13th, 2011, 02:41 PM
  5. Writing in a file using Java
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: August 13th, 2008, 06:45 AM