Question

I am trying to upload/delete a file to webdav server using HttpClient. However, none is working whenever I have a file name consist of space . I got a error message saying "INVALID URI--- Escaped absolute path not valid".

this my URL = "http://localhost:8080/test file.txt"

private boolean delete(String fileName) {
    HttpClient client = new HttpClient();
    HttpHost host = new HttpHost(WEBDAV_URL, PORT_NUMBER);
    client.getHostConfiguration().setHost(host);
    DeleteMethod del = new DeleteMethod(WEBDAV_URL_COMPLETE + fileName);
    try {
        client.executeMethod(del);
        return true;
    } catch (HttpException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

is there any method or URL parse should I use to fix the problem

thanks

EDIT, FOUND the solution by replace space with "%20".

**

URL.replaceAll(" ","%20")

**

Was it helpful?

Solution

I used this and get what I want...

URL.replaceAll(" ","%20")

OTHER TIPS

use java.net.URLEncoder.encode

or replace your spaces with '+'

You should simply rename your file as:

test_file.txt or textFile.txt

It is common standard to never use spaces when coding variables or creating files for such.

Use test_file (snake case) or textFile (camelCase).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top