Here you can find the source of getTimestampedPNGFile(File saveDir)
private static File getTimestampedPNGFile(File saveDir)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss"); private static File getTimestampedPNGFile(File saveDir) { String s = DATE_FORMAT.format(new Date()).toString(); int i = 1; while (true) { File file1 = new File(saveDir, s + (i == 1 ? "" : "_" + i) + ".png"); if (!file1.exists()) { return file1; }/*from ww w. j a v a 2s .co m*/ ++i; } } }