嵌入式小程序无法读取文件
我想这将是一个非常基本的问题,因为我不太熟悉小程序部署:我被要求将 Swing 应用程序转换为小程序并将其嵌入到网页中。该小程序通过读取文本文件(与 .class 文件位于同一目录中)中的行来构建其知识库,当我从小程序查看器启动它时,它可以毫无问题地读取文件。
然而,嵌入后,它无法读取文件并触发异常处理。也许这是这些安全限制之一?
我使用 File、FileReader 和 LineNumberReader 来读取此文档。
附加问题:图像也会发生这种情况,其中小程序根本无法运行。我通过将所述图像放入 HTML 文件中暂时解决了这个问题,但它可以做得更好。
I imagine this would be a very rudimentary problem, since I am not quite familiar with applet deployments: I was made to convert a Swing application into an applet and embed it to a webpage. This applet constructs its knowledge base by reading lines from a text file (in the same directory as the .class file), and when I launched it from the applet viewer it reads the file with no problem.
Upon embedding, however, it fails to read the file and the exception handling is triggered. Perhaps this is one of those security restrictions?
I use File, FileReader, and LineNumberReader to read this document.
Additional problem: this also happens with images, where the applet would not run at all. I temporarily got around this by placing said images within an HTML file, but it could be done much better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试直接使用文件加载它 - 使用Class.getResourceAsStream 和InputStreamReader。换句话说,将其作为资源加载,而不是作为文件加载。
Don't try to load it directly using a file - use
Class.getResourceAsStream
andInputStreamReader
. In other words, load it as a resource rather than as a file.