Java Today createTodayDirectory(File destDir, String inputFileName)

Here you can find the source of createTodayDirectory(File destDir, String inputFileName)

Description

Creates the today directory.

License

Open Source License

Parameter

Parameter Description
destDir the dest dir
inputFileName the input file name

Return

the file

Declaration

public static final File createTodayDirectory(File destDir, String inputFileName) 

Method Source Code


//package com.java2s;
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
 * This code is licensed under the GPL 2.0 license, available at the root
 * application directory./* ww w . j av  a 2  s  .c  o m*/
 */

import java.io.File;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**
     * Creates the today directory.
     *
     * @param destDir
     *            the dest dir
     * @param inputFileName
     *            the input file name
     * @return the file
     */
    public static final File createTodayDirectory(File destDir, String inputFileName) {
        return createTodayDirectory(destDir, inputFileName, false);
    }

    /**
     * Creates the today directory.
     *
     * @param destDir
     *            the dest dir
     * @param inputFileName
     *            the input file name
     * @param withTime
     *            the with time
     * @return the file
     */
    public static final File createTodayDirectory(File destDir, String inputFileName, final boolean withTime) {
        final SimpleDateFormat SDF = withTime ? new SimpleDateFormat("yyyy_MM_dd_hhmmsss")
                : new SimpleDateFormat("yyyy_MM_dd");
        final String newPath = (new StringBuffer(destDir.getAbsolutePath().trim()).append(File.separatorChar)
                .append(SDF.format(new Date())).append("_").append(inputFileName)).toString();
        File dir = new File(newPath);
        if (!dir.exists()) {
            dir.mkdir();
        }

        return dir;
    }
}

Related

  1. afterToday(String date)
  2. beforeToday(int days)
  3. converTimeToDayStartEnd(long time, long[] out)
  4. createTodayDirectory(File destDir)
  5. createTodayPrefixedDirectory(final String prefix, final File parent)
  6. deletePreviousDay(Calendar today, String temppath)
  7. endOfToday()
  8. formatToday()