RFR 8057113: (fs) Path should have a method to test the filename extension

Brian Burkhalter brian.burkhalter at oracle.com
Fri Feb 16 20:20:29 UTC 2018

Hi Daniel,

On Feb 16, 2018, at 10:32 AM, Daniel Fuchs <daniel.fuchs at oracle.com> wrote:

> As David noted, .vimrc is a filename - not an extension,
> and the Unix/Linux basename command will treat it as such:
> $ basename ~/.vimrc .vimrc
> .vimrc
> I think we should try to honor this expectation.
> However:
> $ basename ~/.vimrc.vimrc .vimrc
> .vimrc

Extrapolating it seems that maybe the extension should be empty if the prefix is one or more dots and there are no more dots in what the basename would return. What then do we do about cases such as .java.policy? It seems the result might better be “policy” than empty.

> So would the code below work?
> String filename = Optional.ofNullable(getFilename())
> 	.map(Object::toString).orElse("");
> int index = filename.lastIndexOf('.');
> if (index > 0) return filename.substring(index+1);
> else return ""

It looks like for the aberration “..foo” the above would return “foo” which I am not sure we would want.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20180216/1112f6fe/attachment.html>

More information about the nio-dev mailing list