RFR: 8298318: (fs) APIs for handling filename extensions [v8]
Brian Burkhalter
bpb at openjdk.org
Fri Mar 15 01:45:40 UTC 2024
On Wed, 13 Mar 2024 23:12:50 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> Add to `java.nio.file.Path` a method `getExtension` to retrieve the `Path`'s extension, and companion methods `removeExtension` and `addExtension`.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>
> 8298318: Add parameter checks for withExtension
The approach we have taken is, firstly, to consider the last period character in the file name, if present, to be a separator only. As such it has no value as part of any name. All periods but this last in the name are treated as regular characters with no special meaning. Secondly, for an extension to have any significance, there must be a root or base of the file name, meaning that the part before the last period must be non-empty. This approach appears to be consistent across all platforms and providers. Whether the file is hidden is irrelevant.
For the cited case `"test."`, the period is part of the file name, and so both `Path.of("test.").withoutExtension().withExtension("txt")` and `Path.of("test.").withExtension("txt")` _should_ result in `test..txt`: the first `.` is part of the file name and the last is a separator. Likewise, both `Path.of("test..dat").withoutExtension().withExtension("txt")` and `Path.of("test..dat").withExtension("txt")` both yield `test..txt`.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16226#issuecomment-1998756900
More information about the nio-dev
mailing list