Search code examples
javahtmljava-web-startjapplet

How can i have local file system access using embed Java application in HTML


I just don't know what the right codes should i put, i already tried so many ways to have an access to read and write. My main goal is when i click the button in Java Application, the download will start.


Solution

  • You can't access the local filesystem from a Java sandbox applet. Reading the documentation What Applets Can and Cannot Do, you will see:

    Sandbox applets cannot perform the following operations:

    • They cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.

    • They cannot connect to or retrieve resources from any third party server (any server other than the server it originated from).

    • They cannot load native libraries.

    • They cannot change the SecurityManager.

    • They cannot create a ClassLoader.

    • They cannot read certain system properties. See System Properties for a list of forbidden system properties.

    If you want to bypass these restrictions you have to use a priviliged applet:

    Privileged applets do not have the security restrictions that are imposed on sandbox applets and can run outside the security sandbox.

    For this, you will need to sign your jar and add the following code snippet in the JNLP file:

    <security>
       <all-permissions/>
    </security>
    

    Then the user has to grant the permission. From the documentation:

    The first time an RIA is launched, the user is prompted for permission to run. The dialog shown provides information about the signer's certificate and indicates if the RIA requests permission to run outside the sandbox. The user can then make an informed decision about running the application.

    Read Security in Rich Internet Applications and Deploying With the Applet Tag for more information.