RFR: 8298318: (fs) APIs for handling filename extensions
Brian Burkhalter
bpb at openjdk.org
Tue Oct 17 20:00:39 UTC 2023
On Tue, 17 Oct 2023 19:52:14 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`.
This request follows from previous work outlined in this [nio-dev thread](https://mail.openjdk.org/pipermail/nio-dev/2023-October/015084.html).
For a given `Path` `p`, the following invariant obtains:
assert p.equals(p.removeExtension().addExtension(p.getExtension()));
Replacing an extension may be accomplished by composing the removal and addition methods as:
jshell> Path losslessImage = Path.of("photo.png");
losslessImage ==> photo.png
jshell> Path lossyImage = losslessImage.removeExtension().addExtension("jpg");
lossyImage ==> photo.jpg
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16226#issuecomment-1767071295
More information about the nio-dev
mailing list