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 Alternatives to getCodeBase() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Alternatives to getCodeBase()" Watch "Alternatives to getCodeBase()" New topic
Author

Alternatives to getCodeBase()

Sean McGurk
Greenhorn

Joined: Jun 05, 2001
Posts: 21
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

Joined: Jun 05, 2001
Posts: 21
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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alternatives to getCodeBase()
 
Similar Threads
Applets Writing to File
getCodeBase() rules
Writing Image from Applet
Controling the browser
open URL in specific frame.