Create file name using date and time

后端 未结 5 1815
清酒与你
清酒与你 2020-12-14 00:31

I hope you could help me, I\'m trying to call in the date from another class and looks like \"2011-03-09 06-57-40\", I want to use this to create the file below but everytim

5条回答
  •  一整个雨季
    2020-12-14 00:56

    To create a file named the current date/time:

    Date date = new Date() ;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss") ;
    File file = new File(dateFormat.format(date) + ".tsv") ;
    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write("Writing to file");
    out.close();
    

提交回复
热议问题