-4

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

Kayaman
  • 72,141
  • 5
  • 83
  • 121
ray
  • 11
  • 2
  • 2
    Welcome to StackOverflow. Please take [the tour](http://stackoverflow.com/tour) to see what kind of questions can be asked here and how to ask them. – Kayaman Apr 21 '16 at 06:27
  • 4
    Stackoverflow is not a place where you drop requirements and other people do the work for you. You are expected to show us what you coded so far; and then we help with specific problems. Questions as "show me everything I need to get this done" are not welcome here. – GhostCat Apr 21 '16 at 06:27
  • 1
    there are like tons of working example in the internet. you havent even tried. – Priyamal Apr 21 '16 at 06:29
  • i have looked there are none – ray Apr 21 '16 at 06:37
  • 1
    @toby Don't lie to us. We know there are plenty of examples on the internet. Even on this site. All you need to do is spend some time searching, instead of relying on other people to do your work for you. – Kayaman Apr 21 '16 at 06:40
  • @Kayaman Couldn't agree more, there are plenty of examples like this on SO. – this.user3272243 Apr 21 '16 at 06:46
  • @toby I think that you are not getting that we are not here to do you the job, we are here to help you with something you have already tried out. Don't try the "show me" trick over here. – this.user3272243 Apr 21 '16 at 06:49
  • i just want to do this for fun – ray Apr 21 '16 at 06:50
  • @toby ... No comments. – this.user3272243 Apr 21 '16 at 06:51

1 Answers1

0

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();
itzmebibin
  • 9,199
  • 8
  • 48
  • 62