0

我在使用 JApplet 和 Java Web Start 时尝试读取文本文件时遇到问题,基本上我有一个文件,其中包含我希望读取的用户数据。文本文件存储在 Web 服务器上。这是代码:

company.readCompanyFile("file:///C:/Users/Chris/Desktop/ArFile Clients/" + companyName + "/"
                    + companyName + ".cmp");

readCompanyFile 函数是:

public void readCompanyFile(String cname)
{
    try
    {
        BufferedReader br = new BufferedReader(new FileReader(cname));

        name = br.readLine();
        quota = Float.parseFloat(br.readLine());

        String s;
        while ((s = br.readLine()) != null)
        {
            String[] parts = s.split(":");

            metadataFields.add(parts);
        }

        br.close();
    }
    catch(IOException e)
    {
        System.out.println("File does not exist, or has invalid format");
    }
}

尝试通过 java web start 启动时会引发以下错误

BadFieldException[ The field <extension>href has an invalid value: C:\Users\Chris\Desktop\ArFile Clients,C:\Users\Chris\Desktop\ArFile Clients]
    at com.sun.javaws.jnl.XMLUtils.getAttributeURL(Unknown Source)
    at com.sun.javaws.jnl.XMLUtils.getRequiredURL(Unknown Source)
    at com.sun.javaws.jnl.XMLFormat.handleResourceElement(Unknown Source)
    at com.sun.javaws.jnl.XMLFormat.access$800(Unknown Source)
    at com.sun.javaws.jnl.XMLFormat$2$1.visitElement(Unknown Source)
    at com.sun.javaws.jnl.XMLUtils.visitChildrenElements(Unknown Source)
    at com.sun.javaws.jnl.XMLFormat$2.visitElement(Unknown Source)
    at com.sun.javaws.jnl.XMLUtils.visitElements(Unknown Source)
    at com.sun.javaws.jnl.XMLFormat.buildResourcesDesc(Unknown Source)
    at com.sun.javaws.jnl.XMLFormat.parse(Unknown Source)
    at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
    at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
    at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptorFromCache(Unknown Source)
    at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptorFromCache(Unknown Source)
    at sun.plugin2.applet.JNLP2Manager.initialize(Unknown Source)
    at sun.plugin2.main.client.PluginMain.initManager(Unknown Source)
    at sun.plugin2.main.client.PluginMain.access$200(Unknown Source)
    at sun.plugin2.main.client.PluginMain$2.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Error while initializing manager: BadFieldException[ The field <extension>href has an invalid value: C:\Users\Chris\Desktop\ArFile Clients,C:\Users\Chris\Desktop\ArFile Clients], bail out
4

1 回答 1

2

文本文件存储在 Web 服务器上。

...而小程序在客户端计算机上运行。它将如何读取文件?

您必须使其可通过网络访问,例如通过 HTTP(将其放在服务器上的小程序旁边)。

此外,该堆栈跟踪似乎与您的代码没有任何关系。看起来 Webstart 无法解析部署描述符(也可能是因为引用了服务器磁盘上的文件)。

于 2012-06-18T07:08:16.293 回答