...

View Full Version : trying to read file...



alaios
04-24-2004, 10:25 AM
String theName=getParameter("name");
if (theName==null)
theName="default.txt";
try {

FileReader look= new FileReader(theName);
BufferedReader buff = new BufferedReader(look);
boolean eof=false;
while(!eof){
theString=buff.readLine();
if (theString==null)
eof=true;
}
look.close();
}
catch(IOException e){
System.out.println("File does not exist " + e.toString());
}
}



This code returns the no error at all at compile-time but these run-time errors


java.security.AccessControlException: access denied (java.io.FilePermission default.txt read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
at java.io.FileInputStream.<init>(FileInputStream.java:100)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:39)
at Package.exercise2.init(exercise2.java:49)
at sun.applet.AppletPanel.run(AppletPanel.java:341)
at java.lang.Thread.run(Thread.java:536)

Suggestion?

black3842
04-25-2004, 09:13 AM
First, check file permissions on file make sure you can read it....
then
You might need to change your security.policy file. So that it reflects IO
permission for your class

something like
grant {
permission java.io.FilePermission "C:\\test\\default.txt", "read";
};

read all about it here....
http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum