Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to access a file from within an applet???

Reply
Thread Tools

how to access a file from within an applet???

 
 
Prem G
Guest
Posts: n/a
 
      04-03-2004
Hi,

I have written a public class, lets call it class1. Within this class,
I have a method (method1) which accesses a file, retrieves a bit of
information from the file, and then returns a vector as output.

If I try to call method1 from any normal class, it works fine and I
get the resultant vector. However, when I try to do the same thing
from within an applet class...

e.g. public class class2 extends Applet {

public void init() {
....
}

public void paint(Graphics g) {
....
}
}

if I try to call method1 from within the paint method above in class2,
it just does not work. Does anyone have any idea why this method would
not work within the paint method above and still work within classes
that do not extend Applet?

Also, is there any good way of debugging the java when it gives
runtime errors within applets? In this case for example, I can view
the applet but when method1 is called, the applet crashes. I know
about using Graphics.drawString("sometext") but in cases such as this,
drawString is not very useful.
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      04-03-2004
Prem G wrote:

> Hi,
>
> I have written a public class, lets call it class1. Within this class,
> I have a method (method1) which accesses a file, retrieves a bit of
> information from the file, and then returns a vector as output.
>
> If I try to call method1 from any normal class, it works fine and I
> get the resultant vector. However, when I try to do the same thing
> from within an applet class...
>
> e.g. public class class2 extends Applet {
>
> public void init() {
> ....
> }
>
> public void paint(Graphics g) {
> ....
> }
> }
>
> if I try to call method1 from within the paint method above in class2,
> it just does not work. Does anyone have any idea why this method would
> not work within the paint method above and still work within classes
> that do not extend Applet?
>
> Also, is there any good way of debugging the java when it gives
> runtime errors within applets? In this case for example, I can view
> the applet but when method1 is called, the applet crashes. I know
> about using Graphics.drawString("sometext") but in cases such as this,
> drawString is not very useful.


Lots of things wrong with this:

first of all: accessing the filesystem is a restricted operation in an
applet, and you won't be allowed to do it unless your applet is signed.

Second, do not read a file from within your paint method. It is only meant
to paint the applet, and could be called several times. The init method
would be a better place to do this.

As for debugging, you can still print to System.out and System.err, and you
can see this if you activate the java console.

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
e.Morr
Guest
Posts: n/a
 
      04-03-2004
Since the applet runs in a browser or sandbox, you cannot access the
client's file system. This is intentional applet behavior. If you're trying
for a file server side, I don't believe you can do that, either.

ed


"Prem G" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I have written a public class, lets call it class1. Within this class,
> I have a method (method1) which accesses a file, retrieves a bit of
> information from the file, and then returns a vector as output.
>
> If I try to call method1 from any normal class, it works fine and I
> get the resultant vector. However, when I try to do the same thing
> from within an applet class...
>
> e.g. public class class2 extends Applet {
>
> public void init() {
> ....
> }
>
> public void paint(Graphics g) {
> ....
> }
> }
>
> if I try to call method1 from within the paint method above in class2,
> it just does not work. Does anyone have any idea why this method would
> not work within the paint method above and still work within classes
> that do not extend Applet?
>
> Also, is there any good way of debugging the java when it gives
> runtime errors within applets? In this case for example, I can view
> the applet but when method1 is called, the applet crashes. I know
> about using Graphics.drawString("sometext") but in cases such as this,
> drawString is not very useful.



 
Reply With Quote
 
Prem G
Guest
Posts: n/a
 
      04-04-2004
Thank you for the advice. Actually, I managed to find a way of
accessing files for read via java.net. I can grant the file
permissions of (777 - read/write/execute for all) and then access the
file via a URL connection to the file's URL.

Yes, I definitely should be doing most of my programming in the init()
method.

Also, I agree that the way I've done it means that it is not secure
since anyone can read this file. However, the applet is part of a User
Interface and so a signed applet may not be that "user friendly" in my
opinion.

Thanks again for the help! Hope I enlightened you back if you were not
aware that there was a way to access files via URLs.

Cheers,
Prem.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
GetElementbyID question - within MasterPage/contentpage - within tables Elmo Watson ASP .Net 1 05-08-2007 05:12 PM
How do I include a server tag within a javascript parameter which is itself within a HTML element event? mark4asp ASP .Net 2 11-07-2006 06:23 AM
Referring to a textbox within a web control within an aspx KatB ASP .Net 0 04-22-2005 07:14 PM
search within a search within a search - looking for better way...my script times out Abby Lee ASP General 5 08-02-2004 04:01 PM



Advertisments