Results 1 to 2 of 2
  1. #1
    javanew is offline Member
    Join Date
    Mar 2010
    Rep Power

    Exclamation problem !! input on GUI to a file

    Please help me,,, what i want to do is writing on a text area by keyboard,,, and printing everything on a file,, but the problem is that the file is not empty and containing some text,,, so IT JUST DELETES WHATS ON THE FILE , !!

    Java Code:
    submit = new JButton("Submit");
    				submit.addActionListener(new ActionListener(){
    					public void actionPerformed(ActionEvent e){
    						PrintWriter pr;
    						string2 = area2.getText(); //copys everything on text area and puts it on string2
    						File file = new File("C://Users//Desktop//aaa.txt");
    						try {
    							pr  = new PrintWriter(file);
    							pr.print(string2); //it prints on file but after deleting my previous text  on file~!!
    						} catch (FileNotFoundException e1) {

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    You might want to use a FileWriter rather than a PrintWriter object. If you check the FileWriter API, you'll see that it has a constructor that takes a String for a file name and a boolean, the latter if true lets you append to a file.

    Again, to get more help and better help, please respond to replies and please read the second link in my signature. I speak from experience as that link has helped me innumerable times.

    Much luck!

Similar Threads

  1. Replies: 8
    Last Post: 05-12-2010, 07:19 PM
  2. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  3. retain value of input type file in a jsp file while being dynamically generated
    By nidhi c in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 02:21 AM
  4. Input data from file to arrays problem
    By PVL268 in forum New To Java
    Replies: 18
    Last Post: 03-16-2009, 05:05 AM
  5. Problem in reading HTML input field while uploading file
    By sudipanand in forum Java Servlet
    Replies: 1
    Last Post: 11-27-2008, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts