File.toUrl, is this a bug? persistent

Marilen Corciovei marilen.corciovei@nemesisit.ro
Sun Apr 13 10:53:00 GMT 2003



Hello, sorry for the persistence guys

While running my application which I finnaly compiled and works 50-60% I
found a problem which can be easy replicated using the following piece
of
code:

public class Main {

    public static void main(String[] args) {
        try{
            File file = new File(args[0]);
            URL url;
            if (file.exists()) {
                url = file.toURL();
            }else{
                url = new URL(args[0]);
            }
            URLConnection conn = url.openConnection();
                BufferedReader buf = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
                String line = buf.readLine();
                while(line!=null){
                    System.out.println("line = " + line);
                    line=buf.readLine();
                }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

If args[0] is a http address for example
(http://nemesisit.rdsnet.ro/index.shtml) everything works ok
If args[0] is a local file I get the following error:

java.io.FileNotFoundException: \c:\thisiscool-gcc\examples\reflect\list:
The
filename, directory name, or volume label syntax is incorrect.

   at __ZN4Main4mainEP6JArrayIPN4java4lang6StringEE
(c:\thisiscool-gcc\examples\reflect\src\Main.java:19)
   at _main (c:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccEhbaaa.i)

Is this a bug?

Len





More information about the Java mailing list