[jcifs] Issues with file names that start with a space

Michael B Allen mba2000 at ioplex.com
Wed Feb 21 20:41:50 GMT 2007

On Wed, 21 Feb 2007 15:00:49 -0500
Jake Goulding <goulding at vivisimo.com> wrote:

> Hey all, I have a share that has a file named " spacey.txt". If I do a 
> listFiles() on the containing directory, I am given the file name 
> "spacey.txt" (notice missing leading space). Then, when I try to get 
> that file, it of course cannot be found. Is there some trick to get 
> these files to be listed properly?

I just looked at this and found that it's a problem with the java.net.URL
class. If you do:

  URL url = new URL("http://server/path", " spacey.txt");

you get:


So the java.net.URL class is being "helpful" and trimming the parameter.

Actually URLStreamHandler.parseURL in jcifs.smb.Handler is the point
of failure.

I think the solution to this would be to save the relative name
part passed to the SmbFile and return it when SmbFile.getName() is
called. Currently the SmbFile.getName() method gets the name from the
conanicalized URL so that everything is using the same code path.

I'll put this on The List.


Michael B Allen
PHP Active Directory SSO

More information about the jcifs mailing list