toby toby - 7 months ago 9
Java Question

Record the current date to a .txt file in Java and saves it?

What's the simplest way to record the current date to a (text) file in Java?
and that saves it so after time you will have a list of dates

BKO BKO
Answer

Try this.

            var tdate =  new Date();
            File file = new File("filename.txt");
            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(tdate.toString());
            bw.close();