Hi there I'm writing to a file so that it creates a back log of the data and time i did something. I've got the program so it writes the data that is needed and also the date and time.

the problem is if you use the program more then once then the time does not update. if you close the program and write to the document again the time is correct but only correct the first time its used.

try
            {
                BufferedWriter out = new BufferedWriter(new FileWriter("BackLog.txt",true));
                out.newLine();
                out.write("" + calander.getTime());
                out.newLine();
                out.write(main.Link("opening") + URLtxt.getText());
                out.newLine();
                out.close();
            }
            catch (IOException e)
            {
            }

this is the code I'm using is there any reason why the calander is not updating??

Any help is appreciated thanks.

because calendar.getTime() retreives a Date object equivalent to the the last date and time set in that Calendar object (which is, seemingly, the current time at the time you created it). Simply use new Date() where you are currently using that, or, if you insist on using the calendar (maybe because of timezone settings, or whatever) then call setTime first.

Thank you for the quick response i went with new Date() as it seems to be the better one to go for because it saves me having to update the calander before.

so my final code now looks like in case anyone needs it

try
            {
                BufferedWriter out = new BufferedWriter(new FileWriter("BackLog.txt",true));
                out.newLine();
                out.write("" + new Date());
                out.newLine();
                out.write(main.Link("amendment") + URLtxt.getText());
                out.newLine();
                out.close();
            }
            catch (IOException e)
            {
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.