Reputation: 5589
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);
}
Upvotes: 1
Views: 6356
Reputation: 61526
You will need to sign the applet unless the file is being accessed from the same server/port that the applet came from.
Upvotes: 1
Reputation: 35246
File theFile = new File(uri);
is not the correct method. You accessing an URL, not a File.
Your code should look like this:
try
{
URL url = new URL(strFile);
InputStream in = url.openStream();
(... read file...)
in.close();
} catch(IOException err)
{
(... process error...)
}
Upvotes: 3
Reputation: 533520
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.
Upvotes: 1