View Full Version : can't read file with Java

05-02-2004, 06:10 PM
Hi .. i want to read a string from a txt file.....
The program returns error at run time from the Java's security class///any idea?

try {
FileInputStream fis = new FileInputStream("README.TXT");
int n;
while ((n = fis.available()) > 0) {
byte[] b = new byte[n];
int result = fis.read(b);
if (result == -1) break;
String s = new String(b);
} // End while
} // End try
catch (IOException e) {System.err.println(e);}

05-03-2004, 09:06 AM
Are you running this from an applet? If so then you don't have permission to access the filesystem. You can include the file in the jar and access it with Class.getResourceAsStream() or host it on the same server that hosts the applet and get it from there.


05-03-2004, 09:44 AM
yep i am executing it from an applet...so what i must do?

05-03-2004, 11:07 AM
Applet's don't have permission to read files from the client computer. You can either include the file in the jar of the applet, and then load the file using ClassLoader's getResource... methods. Or you can put the file on the same server as the jar, and then access it remotely (I'm not too familiar with J2SE but I think you create a Url object or something).


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum