DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=32575>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=32575

           Summary: [IO] FileUtils.toFile( URL ) doesn't deal with URL
                    encoding
           Product: Commons
           Version: 1.0 Final
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: IO
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


If the URL passed to the FileUtils.toFile( URL ) method has been encoded, using
the numeric escapes ( e.g., space => %20 ) then the returned File object cannot
be used to access the file on disk, as the path is wrong. 

One way this can occur is when the URL is returned from
ClassLoader.getResource(), and the path to the resource contains spaces. Suppose
the following code is run from a directory containing a space (say, /tmp/with
space/ or d:\temp\with space\):

public static  void main( String[] args )
    throws Exception
{
    System.out.println( System.getProperty( "java.version" ) );

    URL u = file.class.getResource( "t" );
    System.out.println( u.getFile() );

    File f = FileUtils.toFile( u );
    System.out.println( f );
    System.out.println( f.canRead() );
}

Linux:
1.4.1
/tmp/with%20space/t
/tmp/with%20space/t
false

Windows:
1.4.1_06
/D:/temp/with%20space/t
D:\temp\with%20space\t
false

Tested on 1.4.1, 1.4.2 and 1.5.0.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to