Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:34:46+00:00 2026-06-18T00:34:46+00:00

I have a web app that needs to be able open a file locally

  • 0

I have a web app that needs to be able open a file locally on a client machine, with the ability to save the file after editing. The web app generates a document on the server in a folder that is shared out via WebDAV & FTP and this folder is mounted on the client machine.

I cannot use a file:// type URI as it would not permit saving back to the server.

I intend trying to solve the problem with a small java applet embedded in the web app that handles this file opening, but I am having difficulties with permissions in Java. (Java isn’t my field of expertise). Anyhow, I’ve narrowed the code down to the following:

localfile.html

<html>
<body>
  <input id="input" value="Call from Javascript" type="button" onclick="callApplet('/Users/conor/1.txt')">
  <script type='text/javascript'>
  function callApplet(path) {
    applet = document.getElementById('localfile');
    applet.openFile(path);
  }
  </script>
<applet id="localfile" code="localfile.class" archive="localfile.jar"  width="150" height="50"></applet>
</body>
</html>

localfile.java

import java.applet.*;
import java.awt.*;
import java.util.*;
import java.lang.*;
import java.text.*;
import java.awt.event.*;
import java.io.*;

import java.security.*;

public class localfile extends Applet {
  public localfile() {
    Panel p = new Panel();
    p.add(new Button("Call from Java"));
    add("North",p);
  }
  public void openFile(String path) {
    System.out.println("File: " + path);
    final File ffile = new File(path);
    System.out.println("Got file.");
    if (Desktop.isDesktopSupported()) {
      System.out.println("Desktop is supported.");
      final Desktop desktop = Desktop.getDesktop();
      System.out.println("Got Desktop Handle.");
      try {
        desktop.open(ffile);
      } catch(Exception ex) {
        ex.printStackTrace();
      }
      System.out.println("File Opened.");
    }
  }

  public boolean action(Event evt, Object arg) {
    openFile("/Users/conor/1.txt");
    return true;
  }
}

I have compiled, created a jar file and signed it from the java source.

This produces a page with two buttons – a Java one (for testing) and a Javascript one. The Java button works fine as expected – and I can save the file etc. I want to pass the file path to the applet though so it is really the Javascript button I wish to get working. The Javascript one throws the following though:

Stack Trace

java.security.AccessControlException: access denied ("java.awt.AWTPermission" "showWindowWithoutWarningBanner")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
at java.security.AccessController.checkPermission(AccessController.java:560)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.awt.Desktop.checkAWTPermission(Desktop.java:239)
at java.awt.Desktop.open(Desktop.java:267)
at localfile.openFile(localfile.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)

I have also tried embedding the desktop.open call into a doPrivileged block, as follows:

  AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
      try {
        desktop.open(ffile);
      } catch(Exception ex) {
        ex.printStackTrace();
      }
      return null;
    }
  });

but that throws error for javascript & java buttons as follows:

java.lang.SecurityException: class "localfile$1" does not match trust level of other classes in the same package

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:34:47+00:00Added an answer on June 18, 2026 at 12:34 am

    Got it to work, so thought I’d post the solution here…

    When I was compiling the java file with the doPrivileged call in it, the javac compiler creates two files – localfile.class and localfile$1.class. I wasn’t sure initially what the localfile$1.class was and just presumed it was a temporary file of some sort. It was however a class file corresponding to the anonymous class within the doPrilileged block and needed to be included in the .jar file and properly signed.

    So anyway, html file is as before, and final java file is as follows:

    localfile.java

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.security.*;
    
    public class localfile extends Applet {
    
    private static final long serialVersionUID = 1L;
    
    public localfile() {
      Panel p = new Panel();
      p.add(new Button("Call from Java"));
      add("North",p);
    }
    
    public void openFile(String path) {
      System.out.println("File: " + path);
      final File ffile = new File(path);
      System.out.println("Got file.");
      if (Desktop.isDesktopSupported()) {
        System.out.println("Desktop is supported.");
        final Desktop desktop = Desktop.getDesktop();
        System.out.println("Got Desktop Handle.");
        AccessController.doPrivileged(new PrivilegedAction() {
          public Object run() {
            try {
              desktop.open(ffile);
            } catch(Exception ex) {
              ex.printStackTrace();
            }
            return null;
          }
        });
        System.out.println("File Opened.");
      }
    }
    
    public boolean action(Event evt, Object arg) {
      openFile("/Users/conor/1.txt");
      return true;
    }
    
    }
    

    I also found that there was no need to have the javascript in the html file create the applet and insert it into the DOM. I think this was mentioned in the link @VGR linked to but it worked for me without it.

    Thanks for all the help guys!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web app that needs to be able to convert word documents
I'm writing a simple web app in PHP that needs to have write access
I have a web app that lets a client define a daily rate for
We have a calendar scheduling app that needs to be able to send SMS
I have a .net client app that needs to play some content (images, movies,
I'm making a web app that needs to load and save UTF-8 (Korean, specifically)
I have a web app that runs fine in Visual web developer. But when
I have a web app that reads data from a SQL DB that contains
I have a web app that has a big and complex form (fields, checks,
We have an web app that is talking to Netsuite via Netsuite's web services.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.