0

I am using FileUtils to save from internet some files like this:

            FileUtils.copyURLToFile(
                    new URL(urlPath),
                    new File(destinationPath));

But when trying to download a file which has a space in the name it gives me File not found exception. I've tried URLEncoder, but not helping, tried to replace the space with %20, but not helping me either.

Any help would be apreciated. Thx.

  • 1
    Can you provide an [SSCCE](http://sscce.org/) instead of the single instruction you are having problem with? – araknoid Jul 26 '13 at 07:28
  • use double quotes on your url – pratZ Jul 26 '13 at 07:33
  • The URL is [this](http://pictures.content4us.com/60px/BXL-AC40COMPIL.JPG) – trastevere Aug 05 '13 at 12:40
  • Sorry, this is the right link: [http://pictures.content4us.com/60px/BXL-AC40 COMPIL.JPG](http://pictures.content4us.com/60px/BXL-AC40%20COMPIL.JPG). I could't save it with the above code. There's no need to a SSCCE code, as this one line code does everything. The above link is the urlPath and the destination can be any destination, like c:/test.jpg – trastevere Aug 05 '13 at 12:46

1 Answers1

0

You can use the URLEncoder.encode() method to encode your file path with "Utf-8" charset

urlPath = URLEncoder.encode(urlPath,"UTF-8")
FileUtils.copyURLToFile(new URL(urlPath),new File(destinationPath));
Siva
  • 1,938
  • 1
  • 17
  • 36