Computer Science Canada Making a program for parents..need help. |
Author: | GUImaster [ Wed Jul 07, 2010 8:40 pm ] |
Post subject: | Making a program for parents..need help. |
Im making a program for my parents...and i got stuck. a part of what i need to do is **Using Netbeans 6.8** *Needs Button* *Needs TextField* --------------------------------------------------------------------------------- Check To see if "input.txt" is empty if "input.txt" is empty then write "This is Header" write "----------------" write (Text in TextField) if "input.txt" isnt empty then append at end of file (Text in TextField) -------------------------------------------------------------------------------- i had a basic idea of what i needed to do but it didnt work out for me Thanks in Advance |
Author: | Zren [ Wed Jul 07, 2010 9:08 pm ] | ||||
Post subject: | Re: Making a program for parents..need help. | ||||
Here's some code snippets to point you in a general direction of File Input/Output. Buttons are rather easy in netbeans so that shouldn't be the problem. If ya need more details just ask. To find if the file exist (Copy n Paste, this forum doesn't like the brackets at the end. Or just look for exists yourself): http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/io/File.html#exists() File Size:
For writing to files: [Source]
Don't forget to close or flush the bufferedwriter or nothing will write to file. |
Author: | GUImaster [ Wed Jul 07, 2010 9:49 pm ] | ||
Post subject: | Re: Making a program for parents..need help. | ||
i have import.java.io.*; and this code happens when the button is pressed
thats what i have after using netbeans gui bulder... but it doesnt work for me |
Author: | Zren [ Wed Jul 07, 2010 10:04 pm ] |
Post subject: | RE:Making a program for parents..need help. |
Did you clooooo~se the buffered writer? |
Author: | GUImaster [ Wed Jul 07, 2010 10:06 pm ] |
Post subject: | Re: Making a program for parents..need help. |
i dont exactly know where to close it....the try catch things always throw me off [Update] I closed it in the if statement and i got the same error} Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException |
Author: | GUImaster [ Wed Jul 07, 2010 10:20 pm ] |
Post subject: | Re: Making a program for parents..need help. |
I got it working now...Thanks for the help i changed the if (Temp.compareTo(" ")==0) to if (temp == null) |