creation of file object

I am working on jsp

I want to create a file object with path "http://localhost:8080/examples/"

so i have tried to create file with URI as parameter but i'm not able to succed. so

please do help me. thanks in advance.

actual situation is any remote client must be able to create a file on the server. so please suggest a way for that

[364 byte] By [sragvia] at [2007-11-26 23:59:08]
# 1
You can read/write from/to a remote file by a a java.net.URLConnection: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
prometheuzza at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 2
> I want to create a file object with path " http://localhost:8080/examples/"Stop right there, that's a contradiction in terms. The path of a File object is a pathname on the local machine and it doesn't contain a protocol. What you have there is a URL.
ejpa at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 3
i didnot get you ejp. can you be clearer?
sragvia at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 4

In short: File("http://.../x") will NOT create a remote file. It will never create a remote file.

So just give up there.

Instead, the remote server must implement some protocol

or have some server side code (perhaps JSP, ASP, PHP, PL...) that creates a web page.

You need to coordinate with the server side, and do as it asks.

Eg. An online content management software may have special URLs like

"http://somedomain/cms/createPage?title=ABC&color=RED"

"http://somedomain/cms/deletePage?pageID=123"

...

And you need to find out what they are, and call them appropriately.

KathyMcDonnella at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 5

ok ... ok i got the exact URL but i get an exception by executing the following code

<%@page import="java.io.*,java.util.*,java.lang.*,java.net.*" %>

<%

try{

URL yahoo = new URL("http://<hostpath>/fd/test.jsp");

URLConnection yc = yahoo.openConnection();

BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);

in.close();

}

catch(Exception e)

{

out.print("error");

}

%>

sragvia at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 6
And you don't bother tell us what the exception is?Do you think we are mind-readers?Please, put yourself in our place.
KathyMcDonnella at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 7
i just get some exception raised.when i referred this page http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.htmlat the end of the above mentioned page it says set the proxy host ..... can any one explain me what is it and how to do that.
sragvia at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 8

> i just get some exception raised.

No. Exception has a name, a message, and a stack trace.

Print them.

It will give you a LOT OF ideas on what went wrong.

>

> when i referred this page

> http://java.sun.com/docs/books/tutorial/networking/url

> s/readingURL.html

>

> at the end of the above mentioned page it says set

> the proxy host ..... can any one explain me what is

> it and how to do that.

>

Proxy could be an issue. But are you using a proxy on your test machine?

If not, then it is NOT the source of your problem.

KathyMcDonnella at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 9

the exception raised is the following one.

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

java.io.IOException: Server returned HTTP response code: 500 for URL:

sragvia at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 10

>

> Server returned HTTP response code: 500 for URL

>

Ah, good. HTTP500 is a well known error code.

That means the remote server could not even serve the page!

Forget about using Java program.

Just type "http://<hostpath>/fd/test.jsp" into your web browser.

The web browser should say "HTTP 500: Internal Server Error".

The server side code is bad.

So it is not the fault of your client code. It's on the server side.

Edit: Oh wait, are you also the author of the server side code "test.jsp"?

If so, then it's your fault then.

KathyMcDonnella at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 11
tell me KathyMcDonnellcant we create a file using URL /URI on the same machine we are executing the program?Message was edited by: sragvi
sragvia at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 12

> tell me KathyMcDonnellcant we create a file using

> URL /URI on the same machine we are executing the

> program?

No. URL/URI are interpreted by the server side environment (eg. Apache or Tomcat...)

which will translate something like "http://abc.com/home.html"

into something like "/Documents/ABC.COM/webroot/home.html"...

It is a totally webserver-specific operation, and you need to convert URL/URI

into the local pathname using the webserver facilities.

Instead, if you want to create a local file "C:\Home\ABC.html", then do that.

Don't create "new File("http://abc.com/def/ghi/abc.html") and expect Java to know

that it means "C:\Home\ABC.html"

KathyMcDonnella at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...
# 13
ok man i am able to do it KathyMcDonnell . Thanks a lot for your patience.Actually I am new to these forums and java so I am not able to express my problem clearly.Anyways thanks for your help.
sragvia at 2007-7-11 15:47:43 > top of Java-index,Core,Core APIs...