Forum Stats

  • 3,814,226 Users
  • 2,258,845 Discussions
  • 7,892,628 Comments

Discussions

Loading a file with an applet

843811
843811 Member Posts: 49,851
Help!

I'm creating a 2d game applet, and in the game i need to load a file to read in the map to the game. Now, i have some serious problems getting the applet to load the file in browsers like IE and netscape. In appletviever everything's ok, but in the browsers i get security exceptions. Anyone got a sollution to my problem?

(the file i try to load is located in the same directory as the applets class and html file)

/Jon-Mikko

Comments

  • 843811
    843811 Member Posts: 49,851

    Due to the security restrcitions on applets (unsigned), you cannot use "File" to open a file.

    However, a solution to this would be read in the contents of the file as a URL since the file you want to read is in the same directory as the applet.
    URL url=new URL(getDocumentBase(),"yourMapFile.txt");
    DataInputStream dis = new DataInputStrea(url.openStream());
    String line = "";
    while ( (line=dis.readLine()) != nul) {
        // PROCESS LINE HERE
    }
This discussion has been closed.