【发布时间】:2012-06-19 13:38:51
【问题描述】:
我有一个小程序,它的部分设计目的是(仅)读取文本文件并以此为基础制作内容。在我的小程序中,这就是我所拥有的读取文件的“读取”方法:
public void read (String file1) throws IOException
{
str.removeAllElements (); // str is a global vector
BufferedReader dia = new BufferedReader (new FileReader (file1));
for (;;)
{
strc = dia.readLine ();
if (strc == null)
break;
str.add (strc);
}
}
当我通过 JVM 运行它时效果很好,但是当我将它放到网上时,即使它们托管在同一服务器和文件夹上,我想要访问的文件也无法访问。
我的小程序的 HTML 如下所示:
<applet
codebase = "[the url that hosts my class and text files]"
code = "[my class file].class"
width = ###
height = ###>
</applet>
我得到的具体错误是:
AccessControlException
access denied ("java.io.FilePermission" "dial1.txt" "read")
所以如果有人能帮忙,那就太棒了!
【问题讨论】:
-
我知道这主要用于访问本地系统文件,我需要访问服务器上的文件(与我的 .class 文件位于同一目录中...除非从服务器和本地系统文件类似,我认为不需要做文章中提到的任何项目。
-
需要通过http协议通过url访问文件
标签: java applet file-permissions