geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Blewitt <Alex.Blew...@ioshq.com>
Subject Re: [core] Directories w/spaces
Date Tue, 26 Aug 2003 16:57:09 GMT

On Tuesday, Aug 26, 2003, at 17:48 Europe/London, Ned G wrote:

> Note: I have tried to compile the code below on windows XP and Windows 
> 2003
> server
> code throws ArrayIndexOutOfBoundsException exception.

That only happens when run without an argument. It was a demonstration 
piece of code, and when running you should provide the name of a file 
with a space in the middle encoded as %20.

java Test "file:///C:\Program%20Files\test.txt"

If run without an argument, you'll get the AIOOBE. It was meant as a 
demonstration that it's possible to use a URI to do this.

note that if the URI instantiation is changed to

File file = new File(new URI("file",null,u,null));

then you don't need to specify file:/// and nor do you need to escape 
the space. So using the above in place, you can do
java Test "c:\Program Files\test.txt"

and it will automatically create an escaped space using the URI.

Alex.

> import java.net.*;
> import java.io.*;
> public class Test {
>    public static void main(String args[]) throws Exception {
>      String u = args[0];
>      System.out.println("\"" + u + "\"");
>      System.out.println(new URI(u));
>      System.out.println(new File(new URI(u)));
>      File file = new File(new URI(u));
>      FileInputStream fin = new FileInputStream(file);
>      byte buffer[] = new byte[1024];
>      fin.read(buffer);
>      System.out.println("Data:");
>      System.out.write(buffer);
>      System.out.println("eData");
>
>      }
>      }


Mime
View raw message