Using a file from the web

Hi all,

I am interacting with a third-party program (i.e., one that I can't edit) that needs the path of a file (specifically, a NetLogo file).

If I set

path ="/Absolute/path/on/computer/myfile.nlogo"

NetLogo.open(path);

Everything works well. However, now I want the myfile.nlogo file to reside on the web.

At first I naiively thought I could simply usepath ="http://url/to/myfile.nlogo";

NetLogo.open(path);

but doing this gives me a java.io.FileNotFoundException error.

So then I read further into how to open a file from a URL, and it looked as if I ought to be able to do this:URL url =new URL("http://url/to/myfile.nlogo");

File file = (File)url.getContent();

NetLogo.open(file.getAbsolutePath());

but doing that gives me a ClassCast exception when setting the file.

How can I use a file on the web in my java program?

Thanks for any help!

Sam

[1058 byte] By [Asbestosa] at [2007-11-27 0:29:14]
# 1
If by "File" you mean a java.io.File object, there is no such thing as a File on the web. If your NetLogo class doesn't have an open(URL) or open(InputStream) method then you are out of luck. Contact the designer and berate them for short-sighted design.
DrClapa at 2007-7-11 22:31:26 > top of Java-index,Java Essentials,Java Programming...
# 2
File has a constructor that takes a uri.(I suspect that won't work but you can try it.)
jschella at 2007-7-11 22:31:26 > top of Java-index,Java Essentials,Java Programming...
# 3
Ok, I got it. Get the inputstream from the web, transfer that to a FileOutputStream for a given TempFile, then pass the absolute ppath of the TempFile to the open(path) method.Thanks for the replies!
Asbestosa at 2007-7-11 22:31:26 > top of Java-index,Java Essentials,Java Programming...