Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-02-2004, 05:10 PM   PM User | #1
alaios
Regular Coder

 
Join Date: Aug 2002
Posts: 433
Thanks: 3
Thanked 0 Times in 0 Posts
alaios is an unknown quantity at this point
can't read file with Java

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);
System.out.print(s);
} // End while
} // End try
catch (IOException e) {System.err.println(e);}
System.out.println();
alaios is offline   Reply With Quote
Old 05-03-2004, 08:06 AM   PM User | #2
shmoove
Regular Coder

 
Join Date: Dec 2003
Posts: 367
Thanks: 0
Thanked 0 Times in 0 Posts
shmoove is an unknown quantity at this point
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.

shmoove
shmoove is offline   Reply With Quote
Old 05-03-2004, 08:44 AM   PM User | #3
alaios
Regular Coder

 
Join Date: Aug 2002
Posts: 433
Thanks: 3
Thanked 0 Times in 0 Posts
alaios is an unknown quantity at this point
axa

yep i am executing it from an applet...so what i must do?
alaios is offline   Reply With Quote
Old 05-03-2004, 10:07 AM   PM User | #4
shmoove
Regular Coder

 
Join Date: Dec 2003
Posts: 367
Thanks: 0
Thanked 0 Times in 0 Posts
shmoove is an unknown quantity at this point
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).

shmoove
shmoove is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04 AM.


Advertisement
Log in to turn off these ads.