1

Recently, I meet a problem when resolve file path by commons-vfs.

  FileObject tmpDestFo = fsm.resolveFile("/tmp/tempfile%2flicense.xml");
  tmpDestFo.copyFrom(destFo);

As the example, what I expect after the copying is a file named 'tempfile%2flicense.xml' is created under '/tmp' directory. But the result is a file named 'license.xml' created in the '/tmp/tempfile' directory.

I think it's caused by the resolveFile API which replace the character '%2f' to '/'. I'm not sure about if other special characters are processed in the same way.

Do you have some idea about the problem? I do want a file whose name include the '%2f'.

Thanks a lot.

Javen
  • 173
  • 3
  • 10

1 Answers1

0

resolveFile() requires an URI, you actually need to escape quite a few characters. You can run a file path through an URL encode, or you can use new File("/tmp/tempfile%2flicense.xml").toURI().toString() (at least for sane file names).

In your case you need to replace % with %25: "/tmp/tempfile%252flicense.xml"

BTW: The %2f is an encoded /, are you sure it is supposed to be named that way?

eckes
  • 10,103
  • 1
  • 59
  • 71