gpt4 book ai didi

java.security.AccessControlException : access denied (java. io.FilePermission 文件读取)

转载 作者:行者123 更新时间:2023-11-29 05:57:06 27 4
gpt4 key购买 nike

下面的代码提示输入文件名和位置的输入框。当我输入 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);

最佳答案

Can I do this without signing jar file?

没问题。插件 2 JRE 允许我们使用 JNLP API 服务从沙盒小程序访问本地文件系统。这是一个 demo. of the file services .

那个演示。是一个自由 float 的应用程序,但对于小程序中的相同内容(没有源代码),请参见 GIFanim .

关于java.security.AccessControlException : access denied (java. io.FilePermission 文件读取),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11648806/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com