Different operating systems have different file name max lengths. Does Java have any limit on file name length when working with files?
The maximum length of a pathname is 256 characters, which includes all parent directories and the filename. 255-character mixed-case long filename is possible only for files, or folders with no sub-folders, at the root folder of any drive.
In Windows 10, you can enable long file name support, which allows file names up to 32,767 characters (although you lose a few characters for mandatory characters that are part of the name).
Explanation: The maximum length of the filename is 8 characters in the DOS operating system. It is commonly known as an 8.3 filename.
Linux has a maximum filename length of 255 characters for most filesystems (including EXT4), and a maximum path of 4096 characters.
Java has no maximum file name length, except obviously for the String max length limit (which is the array max length, i.e. Integer.MAX_VALUE). Maybe some JVMs have a lower limit but I never run into such a problem (and I'm almost certain it would be a bug with respect to Java specifications), certainly OSes can have one.
Windows has a 256 character filename length. Unix has about the same I believe. So while the Java IO may not have a defined length (String length maybe for sure), it would be dependent on the implementation for the operating system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With