By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,368 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,368 IT Pros & Developers. It's quick & easy.

Saving file into local disc using Applet

P: 5

can somebody help me with saving file into local disk
using javascript? I made some sample code which
unfortunately won't work :(.

Applet sample file:

Expand|Select|Wrap|Line Numbers
  1. public class IO extends Applet {
  3.     public void write(String path, String data) {
  4.         try {
  5.             File file = new File(path);
  6.             DataOutputStream dos = new DataOutputStream(
  7.                 new BufferedOutputStream(
  8.                     new FileOutputStream(file)));
  9.             dos.writeBytes(data);
  10.             dos.close();                    
  11.         }
  12.         catch (SecurityException se) {
  13.             System.err.println(se.getMessage());
  14.         }
  15.         catch (IOException ioe) {
  16.             System.err.println(ioe.getMessage());
  17.         }
  18.     }
  20.     public void paint(Graphics g) {
  21.     }
  23. }
Html sample file:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <applet archive="IO.jar" code="IO.class" name="io" width="0" height="0"></applet>
  3. <script type="text/javascript">
  4. function saveText() {
  5.     document.applets[0].write("c:\\test.txt", "Hello World!");
  6. }
  7. saveText();
  8. </script>
  9. </html>
May 25 '09 #1
Share this Question
Share on Google+
5 Replies

Expert 10K+
P: 11,448
What does "doesn't work" mean? Did you get a Permissions exception? If so, there's another thread going on in this forum about the very same subject; you have to make your Applet 'trusted' then by fiddling with a policy file telling the SecurityManager that such an action (writing a file) is an allowed action.

kind regards,

May 25 '09 #2

P: 5
Yes, I got permission exception. But I don't care about this anymore. Finally I found solution! Watch this video here on youtube:
Jul 2 '09 #3

Expert 10K+
P: 11,448
Care to explain how it works? I saw an IO.jar in the text; what code does it contain in its class(es)?

kind regards,

Jul 3 '09 #4

P: 5
Hello, IO.jar contains signed Java class with five basic methods (write, read, remove, exists and browse) for manipulating with files on local hard disc. There isn't big deal to manage this with signed applet. Everyone can do. There is plenty tutorials how to do this. But, when you want to do the same thing with JavaScript interface then you found there is plenty of problems how to manage cooperation between JavaScript and Java to works together correctly. This solution simply solve this problems ;-).
Jul 6 '09 #5

Expert 10K+
P: 11,448
Ah, ok, you still need to use a signed applet; I wondered if you found a tricky way to accomplish the same without a trusted applet' thanks for the reply.

kind regards,

Jul 6 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.