Enum FileSystem
- All Implemented Interfaces:
Serializable, Comparable<FileSystem>
toLegalFileName(String, char).
The starting point of any operation is getCurrent() which gets you the enum for the file system that matches
the OS hosting the running JVM.
- Since:
- 2.7
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionintGets the file allocation block size in bytes.static FileSystemGets the current file system.char[]Gets a cloned copy of the illegal characters for this file system.int[]Gets a cloned copy of the illegal code points for this file system.intGets the maximum length for file names (excluding any folder path).intGets the maximum length for file paths (may include folders).charGets the name separator, '\\' on Windows, '/' on Linux.String[]Gets a cloned copy of the reserved file names.booleanTests whether this file system preserves case.booleanTests whether this file system is case-sensitive.booleanisLegalFileName(CharSequence candidate) Tests if a candidate file name (without a path) is a legal file name.booleanisLegalFileName(CharSequence candidate, Charset charset) Tests if a candidate file name (without a path) is a legal file name.booleanisReservedFileName(CharSequence candidate) Tests whether the given string is a reserved file name.normalizeSeparators(String path) Converts all separators to the Windows separator of backslash.booleanTests whether this file system support driver letters.toLegalFileName(CharSequence candidate, char replacement, Charset charset) Converts a candidate file name (without a path) to a legal file name.toLegalFileName(String candidate, char replacement) Converts a candidate file name (without a path) to a legal file name.static FileSystemReturns the enum constant of this type with the specified name.static FileSystem[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
GENERIC
Generic file system. -
LINUX
Linux file system. -
MAC_OSX
MacOS file system. -
WINDOWS
Windows file system.The reserved characters are defined in the Naming Conventions (microsoft.com).
- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getCurrent
Gets the current file system.- Returns:
- the current file system
-
getBlockSize
Gets the file allocation block size in bytes.- Returns:
- the file allocation block size in bytes.
- Since:
- 2.12.0
-
getIllegalFileNameChars
Gets a cloned copy of the illegal characters for this file system.- Returns:
- the illegal characters for this file system.
-
getIllegalFileNameCodePoints
Gets a cloned copy of the illegal code points for this file system.- Returns:
- the illegal code points for this file system.
- Since:
- 2.12.0
-
getMaxFileNameLength
Gets the maximum length for file names (excluding any folder path).This limit applies only to the file name itself, excluding any parent directories.
The value is expressed in Java
charunits (UTF-16 code units).Note: Because many file systems enforce limits in bytes using a specific encoding rather than in UTF-16 code units, a name that fits this limit may still be rejected by the underlying file system.
Use
isLegalFileName(CharSequence)to check whether a given name is valid for the current file system and charset.However, any file name longer than this limit is guaranteed to be invalid on the current file system.
- Returns:
- the maximum file name length in characters.
-
getMaxPathLength
Gets the maximum length for file paths (may include folders).This value is inclusive of all path components and separators. For a limit of each path component see
getMaxFileNameLength().The value is expressed in Java
charunits (UTF-16 code units) and represents the longest path that can be safely passed to JavaFileandPathAPIs.Note: many operating systems and file systems enforce path length limits in bytes using a specific encoding, rather than in UTF-16 code units. As a result, a path that fits within this limit may still be rejected by the underlying platform.
Conversely, any path longer than this limit is guaranteed to fail with at least some operating system API calls.
- Returns:
- the maximum file path length in characters.
-
getNameSeparator
Gets the name separator, '\\' on Windows, '/' on Linux.- Returns:
- '\\' on Windows, '/' on Linux.
- Since:
- 2.12.0
-
getReservedFileNames
Gets a cloned copy of the reserved file names.- Returns:
- the reserved file names.
-
isCasePreserving
Tests whether this file system preserves case.- Returns:
- Whether this file system preserves case.
-
isCaseSensitive
Tests whether this file system is case-sensitive.- Returns:
- Whether this file system is case-sensitive.
-
isLegalFileName
Tests if a candidate file name (without a path) is a legal file name.Takes a file name like
"filename.ext"or"filename"and checks:- if the file name length is legal
- if the file name is not a reserved file name
- if the file name does not contain illegal characters
- Parameters:
candidate- A candidate file name (without a path) like"filename.ext"or"filename".- Returns:
trueif the candidate name is legal.
-
isLegalFileName
Tests if a candidate file name (without a path) is a legal file name.Takes a file name like
"filename.ext"or"filename"and checks:- if the file name length is legal
- if the file name is not a reserved file name
- if the file name does not contain illegal characters
- Parameters:
candidate- A candidate file name (without a path) like"filename.ext"or"filename".charset- The charset to use when the file name length is measured in bytes.- Returns:
trueif the candidate name is legal.- Since:
- 2.21.0
-
isReservedFileName
Tests whether the given string is a reserved file name.- Parameters:
candidate- the string to test.- Returns:
trueif the given string is a reserved file name.
-
normalizeSeparators
Converts all separators to the Windows separator of backslash.- Parameters:
path- the path to be changed, null ignored.- Returns:
- the updated path.
- Since:
- 2.12.0
-
supportsDriveLetter
Tests whether this file system support driver letters.Windows supports driver letters as do other operating systems. Whether these other OS's still support Java like OS/2, is a different matter.
- Returns:
- whether this file system support driver letters.
- Since:
- 2.9.0
- See Also:
-
toLegalFileName
Converts a candidate file name (without a path) to a legal file name.Takes a file name like
"filename.ext"or"filename"and:- replaces illegal characters by the given replacement character
- truncates the name to
getMaxFileNameLength()if necessary
- Parameters:
candidate- A candidate file name (without a path) like"filename.ext"or"filename".replacement- Illegal characters in the candidate name are replaced by this character.charset- The charset to use when the file name length is measured in bytes.- Returns:
- a String without illegal characters.
- Since:
- 2.21.0
-
toLegalFileName
Converts a candidate file name (without a path) to a legal file name.Takes a file name like
"filename.ext"or"filename"and:- replaces illegal characters by the given replacement character
- truncates the name to
getMaxFileNameLength()if necessary
- Parameters:
candidate- A candidate file name (without a path) like"filename.ext"or"filename".replacement- Illegal characters in the candidate name are replaced by this character.- Returns:
- a String without illegal characters.
-