Friday, March 23, 2012

Java URL class is Buggered to Buggery

Take this bit of code:

URL url = new URL("");

What should "url.getFile()" return?  I would have guessed the string "test.php".  But it returns "/forums/test.php", which seems to be including the path as far as I can see.

The javadoc actually says "Gets the file name of this URL", but then goes on to contradict itself in the very next sentence with "The returned file portion will be the same as getPath().".  Is it me or Oracle[/Sun] that needs to go back to programming school and learn about the difference between a path and a filename?  Or maybe there is a subtle but massive difference between a "file name" and a "filename".

Also, AFAICT there's no way to get the (what I would call) filename, i.e. "test.php" in the example above.

No comments: