Skip to main content
gamedev.net
🔒 Locked

[java] Another Newbie to applet question

Started by Lucidquiet Sep 8, 2006 at 11:25 AM 1 replies 750+ views
Original Post
Lucidquiet
Lucidquiet
What is the best way to retrieve a file associated with an applet (that is in the same or relative directory) from where the applet is served up from? Can and does an applet need to create a socket and then do an HttpGet to get the contents of a file? Or is this ability some how built into the Applet stuff? Sorry if this is stuff that is obvious in the applet package api doc. Some times if you ask a question you get an answer and some other useful stuff...sometimes. Thanks a lot, L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Paclaw
Paclaw
include it in the jar. Then you access the file just normal inside the jar. So let say you have package xxx and class A with a gif.

+ xxx
+ A.class
+ img.gif

class A
{
//...
//inside A
URL img = this.getClass().getRessource("./img.gif");

}
Paclaw
CaptainJester
CaptainJester
As Paclaw said, it is better to package everything up in a jar. However to do it the way you want just do something like this:
new URL(getDocumentBase(), "myfile.txt").openStream();
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.