• 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

Alternatives to getCodeBase()

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks!
By using the FileOutputStream class, I am able to write to a file located in the same directory as my applet. However, I am unable to read from a file as I am unable to create a URL.
I cannot state something like:

as the program that I am running is not an applet, but rather a java GUI program whose methods are accessed by an applet. It extends Frame, not applet.
Therefore, getCodeBase() is not recognised.
Are there any other protocols that do the same thing i.e. that allow reading from a file.
Regards,
Sean
 
Sean McGurk
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay;
I am now able to state the following:

where SpellCheck is the name of the applet that loads the GUI.
But I am still unable to state:

As this gives me an error message. Anyone know how I might work around this or suggest alternatives?
Regards,
Sean
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the proper syntax:
URL url = new URL(spellcheck.getCodeBase(), "words.txt");
But no matter how you spell it, or what mechanism you try, the sandbox rules still have the final say. A Java Application can write files, an applet running in the AppletView can write files, but an appplet in a web browser can only write files if it has been authorized and signed.
 
I AM MIGHTY! Especially when I hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic