Connecting Tech Pros Worldwide Help | Site Map

Saving file into local disc using Applet

  #1  
Old May 25th, 2009, 02:26 PM
Newbie
 
Join Date: Apr 2009
Posts: 5
Hello,

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 {
  2.  
  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.     }
  19.  
  20.     public void paint(Graphics g) {
  21.     }
  22.  
  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>
  #2  
Old May 25th, 2009, 02:33 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Saving file into local disc using Applet


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,

Jos
  #3  
Old July 2nd, 2009, 07:50 PM
Newbie
 
Join Date: Apr 2009
Posts: 5

re: Saving file into local disc using Applet


Quote:
Originally Posted by JosAH View Post
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,

Jos
Yes, I got permission exception. But I don't care about this anymore. Finally I found solution! Watch this video here on youtube: http://www.youtube.com/watch?v=wqpwyAAhKGg
  #4  
Old July 3rd, 2009, 02:41 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Saving file into local disc using Applet


Quote:
Originally Posted by JohnLorac View Post
Yes, I got permission exception. But I don't care about this anymore. Finally I found solution! Watch this video here on youtube: http://www.youtube.com/watch?v=wqpwyAAhKGg
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,

Jos
  #5  
Old July 6th, 2009, 01:03 PM
Newbie
 
Join Date: Apr 2009
Posts: 5

re: Saving file into local disc using Applet


Quote:
Originally Posted by JosAH View Post
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,

Jos
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 ;-).
  #6  
Old July 6th, 2009, 02:48 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Saving file into local disc using Applet


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,

Jos
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java and PHP Georg Andersson answers 2 July 18th, 2005 12:30 AM