Serguey Asael Shinder: URLEncoder is form encoding, so a space becomes a plus sign in your path
This looks like the obvious way to put a user-supplied name into a link:
String url = "https://example.com/files/"
+ URLEncoder.encode("annual report.pdf", StandardCharsets.UTF_8);
// https://example.com/files/annual+report.pdf

The class name promises URL encoding. The javadoc of java.net.URLEncoder promises something narrower. Its first sentence calls it a "utility class for HTML form encoding", and its methods translate a string "into application/x-www-form-urlencoded format". The rules that follow are the form rules: letters and digits stay, the four characters ., -, * and _ stay, every other character becomes %xy bytes in the chosen charset, and "the space character is converted into a plus sign".
That last rule is the trap. In a form body or a query string, the receiving side decodes + back to a space, because it is decoding the same format. A path segment is not a form. A server or framework that decodes the path as a path has no reason to treat + as anything but a plus, so annual+report.pdf can arrive as a file name with a plus in it, and the lookup fails or finds a different file.
The javadoc's own example shows the format at work: with UTF-8, "The string ü@foo-bar" becomes The+string+%C3%BC%40foo-bar. Every space turned into +, and only because the target is a form.
Two habits follow. Use URLEncoder only for what it names: query parameters and form bodies. For a path, build the address with a type that knows the parts of a URI, for example the multi-argument constructors of java.net.URI, which, in that javadoc's words, "quote illegal characters as required by the components in which they appear", and quote a space as %20, not +.
And never call the one-argument encode(String). The javadoc marks it deprecated because "the resulting string may vary depending on the default charset". Pass StandardCharsets.UTF_8 every time, so the bytes behind each %xy do not depend on the machine.