Saving file into local disc using Applet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohnLorac
    New Member
    • Apr 2009
    • 5

    Saving file into local disc using Applet

    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:

    Code:
    public class IO extends Applet {
    
    	public void write(String path, String data) {
    		try {
    			File file = new File(path);
    			DataOutputStream dos = new DataOutputStream(
    				new BufferedOutputStream(
    					new FileOutputStream(file)));
    			dos.writeBytes(data);
    			dos.close();					
    		}
    		catch (SecurityException se) {
    			System.err.println(se.getMessage());
    		}
    		catch (IOException ioe) {
    			System.err.println(ioe.getMessage());
    		}
    	}
    
    	public void paint(Graphics g) {
    	}
    
    }
    Html sample file:

    Code:
    <html>
    <applet archive="IO.jar" code="IO.class" name="io" width="0" height="0"></applet>
    <script type="text/javascript">
    function saveText() {
    	document.applets[0].write("c:\\test.txt", "Hello World!");
    }
    saveText();
    </script>
    </html>
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    • JohnLorac
      New Member
      • Apr 2009
      • 5

      #3
      Originally posted by JosAH
      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

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by JohnLorac
        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

        Comment

        • JohnLorac
          New Member
          • Apr 2009
          • 5

          #5
          Originally posted by JosAH
          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 ;-).

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            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

            Comment

            Working...