在小程序中读取文件 [英] read file in an applet

查看:40
本文介绍了在小程序中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想读出位于服务器上的文件.我通过参数获取文件的路径

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

引起:java.lang.IllegalArgumentException:URI 方案不是文件"

Caused by: java.lang.IllegalArgumentException: URI scheme is not "file"

谁能给我一个提示?

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);
                        } 

推荐答案

您正在尝试将文件作为文件打开,该文件不遵循 file://uri,正如错误所暗示的那样.

You are trying open as a file, something which doesn't follow the file:// uri, as the error suggests.

如果你想使用 URL,我建议你只使用 url.openStream() ,它应该更简单.

If you want to use a URL, I suggest you just use url.openStream() which should be simpler.

这篇关于在小程序中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆