Last active
August 29, 2015 14:06
-
-
Save adixchen/e11be89091dea9170e23 to your computer and use it in GitHub Desktop.
Method showing how to create a "weeknum" directory in Java and build a file name/file path having the current timestamp to the minute in it...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String getOutputFilePath() throws Exception { | |
//create if not existent a "weeknum" directory in the given "output.directory.base" directory | |
Date now = new Date(); | |
Calendar calendar = Calendar.getInstance(); | |
calendar.setTime(now); | |
int weeknum = calendar.get(Calendar.WEEK_OF_YEAR); | |
String targetDirPath = System.getProperty("output.directory.base") + String.valueOf(weeknum); | |
File targetDirectory = new File(targetDirPath); | |
if(!targetDirectory.exists()){ | |
boolean created = targetDirectory.mkdir(); | |
if(!created){ | |
throw new Exception("Target directory could not be created"); | |
} | |
} | |
//build the file name based on current time to be placed in the "weeknum" directory | |
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm"); | |
String outputFileName = "suggestedPodcasts " + dateFormat.format(now) + ".csv"; | |
String filePath = targetDirPath + "/" + outputFileName; | |
return filePath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment