public class FileNameUtils
extends java.lang.Object
This static class provides various utility methods for manipulating file and directory names.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FILE_SEPARATOR
File separator.
|
static MimeTypeMapper |
mimeTypeMapper
Static mime type mapper.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
changeFileExtension(java.lang.String fileName,
java.lang.String newExtension)
Change extension of file name.
|
static java.lang.String |
createVersionedFileName(java.lang.String fileName)
Create versioned file name.
|
static java.lang.String |
createVersionedFileName(java.lang.String fileName,
int versionNumber,
java.lang.String versionFormat)
Create versioned file name.
|
static java.lang.String[] |
expandFileNameWildcards(java.lang.String[] wildCardNames)
Expand the file name wildcards.
|
static java.lang.String[] |
expandWildcards(java.lang.String fileSpec)
Expand file name wildcard.
|
static boolean |
fileExists(java.lang.String fileName)
Checks if a file exists.
|
static java.lang.String |
fixFileSeparators(java.lang.String fileName)
Fix file separators.
|
static java.lang.String |
getContentTypeFor(java.lang.String fileName)
Get MIME type for a filename.
|
static java.lang.String |
getFileExtension(java.lang.String fileName,
boolean keepPeriod)
Get file extension from file name.
|
static java.lang.String |
stripPathName(java.lang.String fileName)
Strips path from a file name.
|
public static MimeTypeMapper mimeTypeMapper
public static final java.lang.String FILE_SEPARATOR
public static java.lang.String stripPathName(java.lang.String fileName)
fileName
- File name with possible path.public static java.lang.String changeFileExtension(java.lang.String fileName, java.lang.String newExtension)
fileName
- The file name whose extension is to be changed.newExtension
- The new file name extension.Null returned if file name or new extension null.
public static java.lang.String getFileExtension(java.lang.String fileName, boolean keepPeriod)
fileName
- The file name whose extension is wanted.keepPeriod
- Keep the period in the extension.public static java.lang.String getContentTypeFor(java.lang.String fileName)
fileName
- Name of file for which mime type is desired.When the file name's extension is not found in the mime types hash table, a mime type of "application/octet-stream" is returned.
public static boolean fileExists(java.lang.String fileName)
fileName
- The file name to check for existence.public static java.lang.String[] expandWildcards(java.lang.String fileSpec)
fileSpec
- File spec possibly containing "*" wildcard.public static java.lang.String fixFileSeparators(java.lang.String fileName)
fileName
- File name to fix.Escapes the file separators if they are "\" characters.
public static java.lang.String[] expandFileNameWildcards(java.lang.String[] wildCardNames)
wildCardNames
- File names with possible wildcards.File names expressed as URLs are left untouched and any wildcard characters they contains are left as-is.
public static java.lang.String createVersionedFileName(java.lang.String fileName)
fileName
- Candidate file name.public static java.lang.String createVersionedFileName(java.lang.String fileName, int versionNumber, java.lang.String versionFormat)
fileName
- Candidate file name.versionNumber
- Candidate version number .versionFormat
- PrintF format for version number.