LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   can't read from file in java (https://www.linuxquestions.org/questions/programming-9/cant-read-from-file-in-java-173962/)

alaios 04-24-2004 03:28 AM

can't read from file in java
 
trying to read file...
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?

Looking_Lost 04-24-2004 04:19 AM

Do a google search on reading file from an applet.

Mega Man X 04-24-2004 05:34 AM

http://www.particle.kth.se/~fmi/kurs...dByApplet.html

Read is no problem, as long as it's local. I doubt that you can write to file though, Java blocks those things for security reasons :)


All times are GMT -5. The time now is 11:23 AM.