繁体   English   中英

java.security.AccessControlException:拒绝访问(java.io.FilePermission文件读取)

[英]java.security.AccessControlException: access denied (java.io.FilePermission file read)

下面的代码提示输入框中的文件名和位置。 当我输入file://C:/test/abc.tiff然后我得到了

java.security.AccessControlException: access denied (java.io.FilePermission \\c\test\abc.tiff read)

代码片段

CMBDocument document = evt.getDocument();
    String docSaveFileName = (String) docToURL.get(document);
     System.out.println("docSaveFileName :"+docSaveFileName);
            docSaveFileName = docSaveFileName.replaceAll("servlet", "annotate");
            System.out.println("modified docSaveFileName :"+docSaveFileName);
            File tempFile = null;
            try {
                if (evt.getSaveAsNew() || document.isModified()) {
                    if (evt.getSaveAsNew()) {
                        docSaveFileName =
                            JOptionPane.showInputDialog(myGenDocViewer,
                                "Enter the name of the file to save the document:");
                    }
                    if (docSaveFileName == null) { // user cancelled
                        return;
                    }

                    currStreamingDocServices.setPreferredFormats(
                        new String[] { document.getMimeType()});

                    if (document.getCanWrite()) {
                        URL url = new URL(docSaveFileName);
                        OutputStream out = null;
                        String protocol = url.getProtocol();
                        String host = url.getHost();
                        // Use FileOutputStream if this URI is for a local file.
                        if (protocol.equals("file") 
                            && (host == null || host.length() == 0 || host.equals("localhost"))) {
                            out = new FileOutputStream(new File(url.getPath()));
                        }

                        else {
                            URLConnection urlCon = url.openConnection();
                            urlCon.setDoInput(false);
                            urlCon.setDoOutput(true);
                            urlCon.setUseCaches(false); // Enable tunneling.
                            if (urlCon instanceof HttpURLConnection) {
                                HttpURLConnection httpCon = (HttpURLConnection) urlCon;
                                httpCon.setRequestMethod("PUT");
                            }
                            urlCon.setRequestProperty("Content-type",document.getWriteMimeType());
                            out = urlCon.getOutputStream();
                        }
                        document.write(out);
                        out.close();
                        document.setModified(false);
                        document.setNew(false);
                        myGenDocViewer.setDocName(document, docSaveFileName);

我可以不签署jar文件吗?

当然可以。 插件2 JRE允许我们使用JNLP API服务从沙盒applet访问本地文件系统。 这是一个演示。 的文件服务

那个演示。 是一个自由浮动的应用程序,但对于applet中的相同(没有源代码),请参阅GIFanim

您使用此代码的应用程序是什么类型的? 如果它是一个applet,你就会触及沙盒问题:applet无法读取或写入文件系统上的文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM