ray
ray

Reputation: 11

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

Upvotes: -4

Views: 236

Answers (1)

itzmebibin
itzmebibin

Reputation: 9439

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();

Upvotes: 0

Related Questions