file not found Error

Hi everybody

I am doing small program to read the content's of file from the local PC using URL class. I have written the following code but i am getting the error as "file not found".

can anybody help me to solve this problem. how to give the path of the file to URL class constructor to read the content's of file.

import java.io.*;

import java.net.*;

class connect

{

publicstaticvoid main(String a[ ])

throws Exception

{

try

{

System.out.println("111111111");

URL u=new URL("http://PC-name/d:/pandurang/key.txt");

System.out.println("22222222222222");

URLConnection uc=u.openConnection();

System.out.println("333333333333333");

InputStream input=uc.getInputStream();

System.out.println("4444444444444");

FileOutputStream op=new FileOutputStream("d:/abc.txt");

System.out.println("5555555555555");

int c;

while((c=input.read())!=-1)

{

System.out.print((char)c);

op.write((char)c);

}

}

catch(Exception e)

{

System.out.print("file not found");

}

}

}

Output:

111111111

22222222222222

333333333333333

file not found

Regards

Bunty

[2245 byte] By [bunty4ua] at [2007-11-27 10:41:01]
# 1

You are trying to use the HTTP protocol which will be serviced using an HTTP server. Even if you have one installed you won't be able to provide an arbitrary file name as part of the URL. An HTTP server normally is very restrictive about what it will serve.

You may be able to use the 'file' protocol

file://d:/pandurang/key.txt

if the file is on the same machine as you are running your program on.

sabre150a at 2007-7-28 19:10:16 > top of Java-index,Core,Core APIs...