tags:

views:

28

answers:

2

toURI method of File transform space character into %20

On windows XP with Java 6

public static void main(String[] args) {

    File f = new File("C:\\My dir\\test.txt");
    URI uri = f.toURI();

    System.out.println(f.getAbsolutePath());
    System.out.println(uri);
}

C:\My dir\test.txt file:/C:/My%20dir/test.txt

+1  A: 

This is because URLs may not contains Space characters, as specified by RFC2396!

Daniel
thank youI have found a solution.
piero
A: 

In fact, it is normal to have an encoding of space. to recreate the file from the URI, we just need to use the approriate constructor

piero