【问题标题】:Java applet - access denied to file on same web serverJava 小程序 - 拒绝访问同一 Web 服务器上的文件
【发布时间】:2011-02-01 04:07:38
【问题描述】:

我编写了一个简单的 Java 小程序来根据 CSV 文件中的一些数据生成技术图像。我将 CSV 文件作为参数传递给小程序:

<applet code = "assaymap.AssayMapApplet" archive = "http://localhost/applet_test/AssayMap.jar" height="600px" width="800px">
    <param name="csvFile" value="http://localhost/applet_test/test.csv">
</applet>

据我了解小程序安全限制,小程序应该能够从它们所在的主机读取数据。

http://www.jalview.org/examples/applets.html 中的这些小程序使用相同的方法,将文本数据文件作为参数传递。所以我不确定为什么我自己的小程序不起作用。

我正在使用 sourceforge 上的 javacsv 项目读取文件。

我读取 CSV 文件的代码是:

public static ArrayList<Assay> getData(String file) throws FileNotFoundException, IOException {

    ArrayList<Assay> assays = new ArrayList<Assay>();

    CsvReader reader = new CsvReader(file);
    reader.readHeaders();
    while (reader.readRecord()){
        int assay_id = Integer.valueOf(reader.get("assay_id"));
        String assay_name = reader.get("assay_name");
        float distance = Float.parseFloat(reader.get("distance"));
        assays.add(new Assay(assay_id, assay_name, distance));
    }

    return assays;
}

我收到的错误消息是:

Error with processing the CSV data.
java.security.AccessControlException: access denied (java.io.FilePermission http:\localhost\applet_test\test.csv read)

【问题讨论】:

  • 您能否提供一些代码供您阅读。您阅读它的方式可能会有所不同。
  • 我已经在实际读取文件的地方添加了代码。

标签: java applet file-permissions


【解决方案1】:

您显然是在尝试使用“http://localhost/applet_test/test.csv”作为文件名而不是 URL。查看 java.net 包中的 URL 和 URLConnection 类,并使用它们来读取内容而不是 java.io.File。

【讨论】:

  • 非常感谢。我现在将从 URL 生成的 InputStream 传递到 CsvReader 并且它工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多