Results 1 to 4 of 4
- 12-01-2012, 02:22 AM #1
Member
- Join Date
- Nov 2012
- Location
- PA
- Posts
- 7
- Rep Power
- 0
Variable Keeps Resetting, I need it to stop, but it is a little bit more complicated.
I am currently working on a project that requires files to be generated from data obtained from the user. The only problem is naming the files. For instance, I need the files to be named File1.txt, File2.txt, File3.txt,etc. When I run this program (it has GUI) and keep it running it will create the files like previously described. However, if I close the program, then run it again, (I assume the variable resets) and it starts back at File1.txt, etc. I need it to, no matter if the program has stopped and started 10000 times, to keep going at that increment. Like I said, I have everything fine except the problem of the variable resetting.
Obviously filenumber is the variable associated with the problem I am having.Java Code:try{ FileWriter toFile = new FileWriter("File" + filenumber + ".txt"); PrintWriter out = new PrintWriter (toFile); //out.println statement will go here out.close(); filenumber++;//increases filenumber by one to change the to-be file's name } catch (IOException e1) { e1.printStackTrace(); }Last edited by gaeronf; 12-01-2012 at 02:39 AM.
- 12-01-2012, 02:44 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 697
- Rep Power
- 6
Re: Variable Keeps Resetting, I need it to stop, but it is a little bit more complica
If you need to maintain the sequence then you have to store this sequence number in a file. This file should store the last file number that have been created. So when your program stopped the last number will be stored in this file. When you run your program the next time it first read the next sequence value from this file and increment it. This way you can always continue the sequence.
Website: Learn Java by Examples
- 12-01-2012, 02:45 AM #3
Member
- Join Date
- Nov 2012
- Location
- PA
- Posts
- 7
- Rep Power
- 0
- 12-01-2012, 03:06 AM #4
Member
- Join Date
- Nov 2012
- Location
- PA
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Resetting graphics
By PhQ in forum New To JavaReplies: 10Last Post: 01-11-2012, 01:03 AM -
Boolean value not resetting
By BillyB in forum New To JavaReplies: 1Last Post: 03-30-2011, 03:28 PM -
Use stop button to stop moving (stop timers) on JPanel
By mneskovic in forum New To JavaReplies: 3Last Post: 07-23-2010, 12:50 PM -
Complicated Method
By Desmond in forum New To JavaReplies: 5Last Post: 03-17-2010, 11:31 AM -
How do stop Eclipse from suggesting variable names?
By Neil_ in forum EclipseReplies: 0Last Post: 04-12-2009, 03:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks