else if(source == btnsave)
{
try
{
String text= ta.getText();
FileWriter fw = new FileWriter ("Nick.java");
BufferedWriter out = new BufferedWriter (fw);
PrintWriter outFile = new PrintWriter (bw);
for(int i=0; i<10; i++)
{
out.write(text);
}
out.close();
}
catch(IOException ioe1){}
}
This is what I have so far, I have messed for hours so I think I may have gone further and further away.
Cheers
sorry, will do that in future.
It compiles, but in this case in the code so far I have specified the file, when I check the file however it is still the same as it was before.
I think it is not saving it out properly, because it does not overwrite what is already in the file.
Cheers
how are you checking if the file is being changed? using a text editor? do you close it down afterwards?
you're ignoring IOExceptions, which is A Bad Idea ™. put some code in that empty catch block, see what's happening. might be that your text editor is keeping the file open, so your code can't overwrite it. but you won't know that's happening because you're ignoring IOExceptions
Another point: it easy to miss methods introduced by superclasses. Check out the methods of JTextComponent -- the superclass of JTextArea. You may find the its [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/JTextComponent.html#read(java.io.Reader,%20java.lang.Object)]read()[/url] and [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/JTextComponent.html#write(java.io.Writer)]write()[/url] methods darn handy.
> Another point: it easy to miss methods introduced by
> superclasses. Check out the methods of JTextComponent
> -- the superclass of JTextArea. You may find the its
> [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swi
> ng/text/JTextComponent.html#read(java.io.Reader,%20jav
> a.lang.Object)]read()[/url] and
> [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swi
> ng/text/JTextComponent.html#write(java.io.Writer)]writ
> e()[/url] methods darn handy.
ah. they are handy, aren't they. wonder if it's time I read a swing tutorial.....