java applet using FileReader I/O

I'm currently a TA teaching a class at Lockheed Martin and loooking for a quick source code java applet which reads a information from a txt file using FileReader and displays it to the screen when the button on the applet is pushed.

anyway you have something lying around that I can use as a working example
been busting butt seaching but have found no luck and I have to have this ready tomorrow.
Your help be appreciated Thank You
angel875Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
BufferedReader in = new BufferedReader(new FileReader(file));
String line = null;
while (null!=(line=in.readLine()))
{
   System.out.println(line);
}

to read from a local file from an applet will require the applet be signed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Do something like:

BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/x.txt")));
String buffer = null;
while ((buffer = in.readLine()) != null) {
      System.out.println(buffer);
}
in.close();
0
objectsCommented:
you could use a JTextArea to display the file contents to screen.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

CEHJCommented:
If you put x.txt into the same directory as the applet class file, you won't have to sign the applet
0
objectsCommented:
Add the above code to the ActionListener for your button

0
objectsCommented:
> If you put x.txt into the same directory as the applet class file, you won't have to sign the applet

you can put it in any directory you want on the server that is visible to the applet.
you need to sign it if want to read files on the *client*.
0
objectsCommented:
this may help:
http://java.sun.com/docs/books/tutorial/applet/index.html

let me know if you have any questions.
0
CEHJCommented:
If you do need it to read files on the client, here's some info about signing the applet:

http://mindprod.com/jgloss/signedApplets.html
0
Tommy BraasCommented:
Hi angel875,

It would be academic dishonesty to provide you with code outright.

A FileReader can be instantiated with either a String path to a file, a File instance or a FileDescriptor. Once instantiated, it can be read from provided the file exists. If the file doesn't exist a FileNotFoundException will be thrown. See http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileReader.html

To display it in an applet, you could add a TextArea to the applet and add the text you read from the file into the text area.
See http://java.sun.com/j2se/1.4.2/docs/api/java/awt/TextArea.html
and http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html

In order to allow an applet to show local file content, the applet needs to be signed. An applet operates in 'sandbox' and it is not allowed to read/write files by default. Please have a look at the following page for a plethora of links http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20060040.html
or check this link out directly: http://www.suitable.com/docs/signing.html

\t
0
Tommy BraasCommented:
damn, it took too long to write my essay....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.