Results 1 to 2 of 2
- 09-20-2010, 11:43 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 49
- Rep Power
- 0
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~!! pr.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } } });
-
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
-
how to change the layout of an input file and write to an output file
By renu in forum New To JavaReplies: 8Last Post: 05-12-2010, 07:19 PM -
count character in text file as input file
By aNNuur in forum New To JavaReplies: 7Last Post: 03-25-2010, 04:01 PM -
retain value of input type file in a jsp file while being dynamically generated
By nidhi c in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 09-27-2009, 02:21 AM -
Input data from file to arrays problem
By PVL268 in forum New To JavaReplies: 18Last Post: 03-16-2009, 05:05 AM -
Problem in reading HTML input field while uploading file
By sudipanand in forum Java ServletReplies: 1Last Post: 11-27-2008, 09:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks