Problem reading file from applet!  
Author Message
Marcus P





PostPosted: 2005-2-4 5:07:00 Top

java-programmer, Problem reading file from applet! Hello!
I'm not too experienced in java and I have a problem reading from a file
with my applet. As I understand the applet is aloud to read from the same
folder as the applet is in.
I have declared a File (that point to my file in the same folder), a
FileReader with try and catch Exception and then I have written
FileReader.read(char c, int, int) with try and catch. The compiler accepts
my code but when I run my applet in appletviewer the promt gives me errors.
Can somebody please help me?
Many, many thanks in advance!
Best regards
Marcus


 
Rhino





PostPosted: 2005-2-4 5:26:00 Top

java-programmer >> Problem reading file from applet!
"Marcus P" <email***@***.com> wrote in message
news:tgwMd.20216$email***@***.com...
> Hello!
> I'm not too experienced in java and I have a problem reading from a file
> with my applet. As I understand the applet is aloud to read from the same
> folder as the applet is in.
> I have declared a File (that point to my file in the same folder), a
> FileReader with try and catch Exception and then I have written
> FileReader.read(char c, int, int) with try and catch. The compiler accepts
> my code but when I run my applet in appletviewer the promt gives me
errors.
> Can somebody please help me?
> Many, many thanks in advance!
> Best regards
> Marcus
>
You haven't shown us any code nor specified the error messages. That makes
it pretty hard for anyone to help you. It may also be useful to know
something about your environment: which version of Java are you running and
what operating system are you using.

Without more information, there's not much that we can do for you.

Rhino


 
Andrew Thompson





PostPosted: 2005-2-4 18:04:00 Top

java-programmer >> Problem reading file from applet! On Thu, 3 Feb 2005 16:25:57 -0500, Rhino wrote:

> "Marcus P" <email***@***.com> wrote in message
> news:tgwMd.20216$email***@***.com...
>> Hello!
>> I'm not too experienced in java and I have a problem reading from a file
>> with my applet. As I understand the applet is aloud to read from the same
>> folder as the applet is in.

The same *host*. That is not the same thing.

With appropriate parameters in the applet element, an applet
can access any file in any (non protected) directory of the
site or disk from which it was delivered.

>> I have declared a File (that point to my file in the same folder), a
>> FileReader with try and catch Exception and then I have written
>> FileReader.read(char c, int, int) with try and catch.

You need to use URL's to get your data. File related objects
will always hit the applet security sandbox restrictions.
<http://www.physci.org/codes/javafaq.jsp#security>
<http://mindprod.com/jgloss/applet.html#RESTRICTIONS>

Use 'getResource to get an URL..
<http://www.physci.org/pc/property.jsp?prop=java.version+java.vendor>

Then load the bytes from the URL, or hand it to something that will.

>>..The compiler accepts
>> my code but when I run my applet in appletviewer the promt gives me
> errors.

> You haven't shown us any code

<http://www.physci.org/codes/sscce.jsp>

>..nor specified the error messages.

<http://www.physci.org/codes/javafaq.jsp#exact>

>..That makes
> it pretty hard for anyone to help you. It may also be useful to know
> something about your environment: which version of Java are you running

<http://www.physci.org/pc/property.jsp?prop=java.version+java.vendor>

...
> Without more information, there's not much that we can do for you.

Spot on. An URL is also handy for applets, especially if they break.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane