Java Utililty Methods File Name Create

List of utility methods to do File Name Create

Description

The list of methods to do File Name Create are organized into topic(s).

Method

StringaddTimeStampGetPostFix(Date now, TimeUnit unit)
add Time Stamp Get Post Fix
if (unit == TimeUnit.MINUTES) {
    return new SimpleDateFormat("yyyy-MM-dd_HH:mm").format(now);
} else if (unit == TimeUnit.HOURS) {
    return new SimpleDateFormat("yyyy-MM-dd_HH").format(now);
} else if (unit == TimeUnit.DAYS) {
    return new SimpleDateFormat("yyyy-MM-dd").format(now);
} else {
    throw new IllegalArgumentException(unit.toString());
...
StringaddTimestampToFilename(Date date, String fileName)
Adds the timestamp to filename.
String[] time = getTimeFormat(date, "yyyy-MM-dd.HH-mm").split("\\.");
return time[0] + "/" + time[1] + fileName;
StringaddTimestampToFilename(String fileName)
add Timestamp To Filename
int pos = fileName.lastIndexOf('.');
String prefix = fileName;
String suffix = "";
if (pos != -1) {
    prefix = fileName.substring(0, pos);
    suffix = fileName.substring(pos);
String newFileName = prefix + timestampForFile() + suffix;
...
StringaddTimeStampToFileName(String name)
add Time Stamp To File Name
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yy 'at' HH.mm.ss", Locale.ENGLISH);
Date currentDate = new Date();
String formattedDate = dateFormat.format(currentDate);
int index = name.lastIndexOf(".");
String mainFName;
if (index != -1) {
    mainFName = name.substring(0, index - 1) + " " + formattedDate
            + name.substring(index - 1, name.length());
...
StringfileName(Class clazz)
file Name
return clazz.getName().replace('.', '/') + ".class";
Stringfilename(final String path)
Return the filename part of a path.
int i = path.lastIndexOf('/');
return (i < 0) ? path : path.substring(i + 1);
StringfileName(String contentFile)
file Name
if (contentFile == null || contentFile.isEmpty()) {
    return "";
int i1 = contentFile.lastIndexOf("/");
int i2 = contentFile.lastIndexOf("\\");
if (i1 > 0 || i2 > 0) {
    return contentFile.substring(Math.max(i1, i2) + 1);
return contentFile;
StringfileName(String file)
Get the file name minus its suffix
int index = file.lastIndexOf(".");
if (index != -1)
    return file.substring(0, index);
else
    return file;
StringfileName(String file, String moduleName)
file Name
String name = file.replaceAll("_drupal_safe_name_", moduleName);
return name;
Stringfilename(String filename)
filename
int dot = filename.lastIndexOf(".");
if (dot == -1) {
    return filename;
return filename.substring(0, dot);