在小程序中读取文件
您好,我想读出服务器上的一个文件。 当我现在启动小程序时,我通过参数获取文件的路径,
<PARAM name=fileToRead value="http://someserver.de/file.txt">
发生以下错误
原因:java.lang.IllegalArgumentException:URI方案不是“文件”
有人能给我提示吗?
BufferedReader file;
String strFile = new String(getParameter("fileToRead"));
URL url = new URL(strFile);
URI uri = url.toURI();
try {
File theFile = new File(uri);
file = new BufferedReader(new FileReader(new File(uri)));
String input = "";
while ((input = file.readLine()) != null) {
words.add(input);
}
} catch (IOException ex) {
Logger.getLogger(Hedgeman.class.getName()).log(Level.SEVERE, null, ex);
}
Hi there I want to read out a file that lies on the server.
I get the path to the file by a parameter
<PARAM name=fileToRead value="http://someserver.de/file.txt">
when I now start the applet following error occurs
Caused by: java.lang.IllegalArgumentException: URI scheme is not "file"
Can someone give me a hint?
BufferedReader file;
String strFile = new String(getParameter("fileToRead"));
URL url = new URL(strFile);
URI uri = url.toURI();
try {
File theFile = new File(uri);
file = new BufferedReader(new FileReader(new File(uri)));
String input = "";
while ((input = file.readLine()) != null) {
words.add(input);
}
} catch (IOException ex) {
Logger.getLogger(Hedgeman.class.getName()).log(Level.SEVERE, null, ex);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在尝试作为文件打开,该文件不遵循 file:// uri,如错误所示。
如果你想使用 URL,我建议你只使用 url.openStream() ,这应该更简单。
You are trying open as a file, something which doesn't follow the file:// uri, as the error suggests.
If you want to use a URL, I suggest you just use url.openStream() which should be simpler.
您将需要对小程序进行签名,除非从小程序来自的同一服务器/端口访问该文件。
You will need to sign the applet unless the file is being accessed from the same server/port that the applet came from.
不是正确的方法。 您访问的是 URL,而不是文件。
您的代码应如下所示:
is not the correct method. You accessing an URL, not a File.
Your code should look like this: