Re: Open a file in JApplet
From: Andrew Thompson (SeeMySites_at_www.invalid)
Date: 08/26/04
- Next message: Johnny Storm: "Re: JAVA and PHP"
- Previous message: Nick Pomfret: "Re: Object Serialization and Reading"
- Maybe in reply to: Paul Lutus: "Re: Open a file in JApplet"
- Next in thread: Paul Lutus: "Re: Open a file in JApplet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Aug 2004 14:20:55 GMT
On 25 Aug 2004 15:46:34 -0700, Jenny wrote:
> I tried to open a file and read it into an JApplet. It does not
> display the string in the file. Could tell me which part of code does
> not run and why?
Part of the problem is that this code ignores errors..
>...Could you tell me how to fix it?
You might start by always ensuring you print an
exception even if, ..perhaps especially if, that
exception or error 'cannot' happen.
>...Thanks a lot. Here
> is the code:
I have not had time to try you complete example Jenny,
but here is the tip I have for you..
> Java file 1:
>
...
> try {
> File f = new File("hello.txt");
> FileInputStream file = new FileInputStream(f);
> byte[] b = new byte[20];
> file.read(b);
> String s = new String(b);
> comp2D.drawString(s,20,20);
> file.close();
> } catch (Exception e) {
// here is the better way to deal with this..
e.printStacktrace();
> }
> }
> }
> }
Once you do that, you should see errors appearing in the
Java console of your browser.. They might look complicated
and scary at first, but the info. on this page might help
you get used to reading and understanding them.
<http://www.physci.org/codes/javafaq.jsp#exact>
It is not just handy, but vital to be able to
start debugging Java problems by using the information
in the stack trace..
There is also information on a different Java group
further down that page, I suspect you might get better
help there for the moment if you are a beginner, it is
<http://www.physci.org/codes/javafaq.jsp#cljh>
People who post there generally take a little extra
time to help the people new to Java.
HTH
-- Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
- Next message: Johnny Storm: "Re: JAVA and PHP"
- Previous message: Nick Pomfret: "Re: Object Serialization and Reading"
- Maybe in reply to: Paul Lutus: "Re: Open a file in JApplet"
- Next in thread: Paul Lutus: "Re: Open a file in JApplet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|