Local file reading by signed applets blocked by Safari

Local file reading by signed applets is blocked on Safari, due to a November 2013 Safari security change.

Steps to reproduce:

Expected behavior:

The expected behavior is what is seen on Windows and on Firefox on the Macintosh.

Actual behavior:


This appeared at the same time as an inability to write local files, as demonstrated at "Local file writing by signed applets blocked by Safari" and the inability of a signed Java applet in Safari to launch new browser windows using Runtime.getRuntime().exec.  


Firefox is not affected, but the issue in Safari can be fixed as follows: Safari > Preferences > Security > Manage Website Settings… > Java > (your site) > Run in Unsafe Mode > Trust

Source code:

import java.awt.*;
import java.applet.*;
import java.io.*;
import java.net.*;

public class localFileRead extends Applet {

public void init()
   setBackground(new Color(255, 240, 200));

public void paint(Graphics g)
     boolean macOS = (System.getProperty("os.name").startsWith("Mac"));
     boolean windowsOS = (System.getProperty("os.name").startsWith("Win"));
     String userHome = System.getProperty("user.home");
     BufferedInputStream bis = null;
     URL rootOnClientURL = null;
     if (macOS) rootOnClientURL = new URL("file", "", "//" + System.getProperty("user.home") + "/");
     else if (windowsOS) rootOnClientURL = new URL("file:/" + userHome.replace('\\', '/') + "/AppData/LocalLow/");
     g.drawString("rootOnClientURL = " + rootOnClientURL, 10, 30);
     URL url = new URL(rootOnClientURL, "localFile.txt");
     bis = new BufferedInputStream(url.openStream(), 32768);
     DataInputStream dataIS = new DataInputStream(bis);
     String s = dataIS.readUTF();
     g.drawString("Reading a local file worked. Its contents are = " + s, 10, 60);
     catch (Exception e)
     g.drawString("Reading a local file didn't work. The Exception is: " + e.getMessage(), 10, 70);
} // END OF Class localFileRead

If you have any insights or comments about this page please contact Mickey Segal.  A listing of  many Java resources is at this link.