3 ms·
I think Java does that. Thanks to its built-in libraries, you can write code that works on multiplie platforms with different file systems. However, you still n
by Hermel 8y ago
I think Java does that. Thanks to its built-in libraries, you can write code that works on multiplie platforms with different file systems. However, you still need to know yourself which characters are legal in which system (for example, ‘:’ is not a legal character in file names on windows, but it is on OS X.
- brazzy 8y agoAt least since Java 7, the API has a concept of a filesystem which can create filesystem-specific Path objects and, if it encounters illegal characters, throws an InvalidPathException that tells you which character was illegal.
- CodesInChaos 8y agoSounds tricky to get right, considering the filesystem can change in the middle of a path.
- brazzy 8y agoI haven't worked extensively with the API, but I believe that it represents filesystem instances accessible to the JVM, not abstract technical filesystems. So in the case of a Unix filesystem tree with various mount points, the FileSystem object would throw the exception iff the path you're trying to construct is illegal for the actual filesystem configuration in the system.
- klodolph 8y ago":" is or is not a legal character in filenames on macOS depending on which API you use! Try saving a file or renaming a file to contain ":" using the GUI. It will not work. However, "/" is fine. Try saving a file or renaming a file to contain "/" using the CLI. It will not work. However, ":" is fine. A ":" in the CLI is translated to "/" in the GUI and vice versa. ":" was the directory separator in Mac OS 9 and earlier, which explains the behavior. The actual on-disk filenames will contain "/", which is translated to ":" for the POSIX API. This is for HFS and HFS+, not sure how APFS changes things.