I have the data for a large hashmap stored in a file.
The applet and file are wrapped in the jar.
It works perfectly as an application and using appletviewer works fine as an applet but it does not work through a browser.
Wondered if anybody could make a suggestion or provide a easy to understand link.
Is there a better way?
I didn't particularly want to iterate through 100k's of records.
Ahhh - I thought it was because it worked using the appletviewer.
I take it it doesn't matter if it's in the same directory?
Can I read the file from the class somehow?
Or is there another way of loading in data? - could I load it as a web page?
Mich Robinson wrote:I take it it doesn't matter if it's in the same directory?
What do you mean, "the same directory"? The applet comes from the server; are you saying this hashmap file should also come from the server? Sure, that's possible. Just set it up in the same directory as the applet and make sure the server is configured to serve it upon request.
You would have to access it via a URL, of course, not as a File, since File would be referring to files on the client and not on the server. The URL would be very much like the URL for the applet, in fact the Applet has classes like getCodeBase() and getDocumentBase() to help you out with that.
Joined: Jun 28, 2009
I essentially wanted to go for something easy as the application itself is quite complicated as it stands. It's a check playing program and the hashmap contained essential endgame positions. The advantage of loading the hashmap from a file was that :
the initial load of the applet would be quicker
most of the time it beats people quite quickly and so doesn't get to an end game
if it was in a seperate file then I could add to the file as time goes on
Turns out doing this is a bit more complicated than I thought so I've decided to just build the hashmap in the program itself and avoid any complications. Thanks for your advice.
PS1) the hashmap would definitely be stored on the server.
PS2) Compressing the hashmap values myself and then putting them in the applet added 600K to the applet. Oddly allowing java to write the hashmap to a file and then reload it meant it created a 2MB file. I was sort of expecting a big saving doing it this way but it didn't appear to be the case.