• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading hashmap from file

 
Ranch Hand
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mich Robinson
Ranch Hand
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic