在一个applet读取文件 [英] read file in an applet

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

问题描述

您好我想读出了位于服务器上的文件。
我由一个参数来获取文件路径

 < PARAM NAME = fileToRead值=htt​​p://someserver.de/file.txt>

当我现在开始小程序出现下列错误

产生的原因:java.lang.IllegalArgumentException异常:URI方案不是文件

有人可以给我一个提示?

  BufferedReader中的文件;
                        字符串strFile =新的String(的getParameter(fileToRead));                        网址URL =新的URL(strFile);
                        的URI的uri = url.toURI();
                        尝试{                            文件theFile =新的文件(URI);
                            文件=新的BufferedReader(新的FileReader(新文件(URI)));                        字符串输入=;                            而((输入= file.readLine())!= NULL){
                               字词。(输入);
                            }
                        }赶上(IOException异常前){
                          。Logger.getLogger(Hedgeman.class.getName())日志(Level.SEVERE,空,前);
                        }


解决方案

您正在尝试为一个文件,这东西不符合文件打开:// URI,因为错误提示

如果你想使用一个网址,我建议你只使用url.openStream()这应该是简单的。

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

解决方案

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.

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

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