<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Hello David,
<div><br>
</div>
<div>Redirecting to nio-dev.<br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On Sep 10, 2025, at 12:01 PM, David Alayachew <davidalayachew@gmail.com> wrote:</div>
<br class="Apple-interchange-newline">
<div><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">One
would expect only fileZ.html to be printed out, but nothing does. The reason why is because path.endsWith(String) is effectively an alias for path.endsWith(Path.of(String)). The confusion being that Path.of(someString) is looking for a file or a directory.
Thus, since there is neither a file nor a folder called "html", the stream prints out nothing.</span></div>
</blockquote>
</div>
<br>
</div>
<div>The specification looks like it is pretty clear about the behavior, especially the implementation note in <a href="https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/nio/file/Path.html#endsWith(java.lang.String)">Path.endsWith(String)</a>:</div>
<div><br>
</div>
<div>"<span style="font-family: -webkit-standard; font-size: medium;">The default implementation is equivalent for this path to:</span></div>
<div>
<pre class="snippet" id="snippet-endsWith(java.lang.String)1"><code class="language-java"> endsWith(getFileSystem().getPath(other));"</code></pre>
<pre class="snippet" id="snippet-endsWith(java.lang.String)1"><font face="Helvetica">What you were expecting sounds like what would be given by</font></pre>
<pre class="snippet" id="snippet-endsWith(java.lang.String)1"><div dir="auto" style="white-space: normal; font-family: Helvetica;">.filter(path -> path.toString().endsWith("html”))</div><div dir="auto" style="white-space: normal; font-family: Helvetica;"><br></div><div dir="auto" style="white-space: normal; font-family: Helvetica;">or better</div><div dir="auto" style="white-space: normal; font-family: Helvetica;"><br></div><div dir="auto" style="white-space: normal; font-family: Helvetica;">.filter(path -> path.getFileName().toString().endsWith("html”))</div><div dir="auto" style="white-space: normal; font-family: Helvetica;"><pre class="snippet" id="snippet-endsWith(java.lang.String)1"><div><span style="font-family: Helvetica;">Is that correct?</span></div></pre></div></pre>
<pre class="snippet" id="snippet-endsWith(java.lang.String)1"><font face="Helvetica">If we could eventually agree on how to handle file extensions, that would help here.</font></pre>
<pre class="snippet" id="snippet-endsWith(java.lang.String)1"><font face="Helvetica">Brian</font></pre>
</div>
</body>
</html>