The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
June 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

reply

Posted by Pavan Kumar Keely on July 02, 2001 at 7:19 AM

> I am writing an applet which contains a TextArea. I want this applet to read text from a text file and display it in the TextArea. I created a File object using the following code :
> File f = new File("Text.txt");
> and then went about reading and displaying text. This approach worked fine when I ran the program in appletviewer. When I tried to run the applet in Internet Explorer the text file could not be loaded. Then I changed the above code like this :
> File f = new File("C:/Java/Text.txt"); giving the full path name.
> This worked fine. But whenever I change directories I have to change the code and recompile. My question is, is there a way to specify the file so that I do not have to write the absolute path? I want to include this applet in my home page where giving the full path name would not be very convenient. Please help.

> Ashok


Hi Ashok,

You can specify the file name at runtime using the "FileDialog".
But remember this is applet and FileDialog takes the frame( parent) in the constructor. For this you have to change this a bit.
Create a frame in the applet, invoke the "FileDialog" in the Frame. But upon clicking "open", or "cancel" don't forget to dispose the frame.

This may solve your problem. If not please feel free to contact me at keelypavan@hotmail.com

Pavan Kumar Keely



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us