File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Reading hashmap from file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Reading hashmap from file" Watch "Reading hashmap from file" New topic
Author

Reading hashmap from file

Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
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.
Thanks


Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41816
    
  62
Applets are not allowed access to the local file system; is the applet signed to work around that? There should be error messages in the Java Console to that effect.


Ping & DNS - my free Android networking tools app
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
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?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Reading hashmap from file