1

以下のコードは、ファイル名と場所の入力ボックスを求めます。私が入る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);
4

2 に答える 2

2

jarファイルに署名せずにこれを行うことはできますか?

確実なこと。プラグイン2JREを使用すると、JNLP APIサービスを使用して、サンドボックス化されたアプレットからローカルファイルシステムにアクセスできます。これがデモです。ファイルサービスの

そのデモ。はフリーフローティングアプリケーションですが、アプレット(ソースコードなし)での同じものについては、GIFanimを参照してください。

于 2012-07-25T12:21:06.413 に答える
1

このコードを使用しているアプリケーションは何ですか? アプレットの場合は、サンドボックスの問題に触れています。アプレットはファイル システム上のファイルを読み書きできません。

于 2012-07-25T11:57:20.430 に答える