Article View: borland.public.jbuilder.java.language
Article #15943File access through applets
From: Jennifer Latham
Date: Mon, 19 Apr 1999 00:00
Date: Mon, 19 Apr 1999 00:00
38 lines
2440 bytes
2440 bytes
I am trying to incorporate some file access into my Java applet. I would
like to keep the data for my program in a file stored in the same directory
as my applet class file. I originally used a BufferedReader along with a
FileReader, but this causes security exceptions to be raised by browsers. I
then switched to a BufferedReader and an InputStreamReader but I then get
the following NullPointerException:
java.lang.NullPointerException
at java.io.InputStreamReader.read(Compiled Code)
at java.io.BufferedReader.fill(Compiled Code)
at java.io.BufferedReader.readLine(Compiled Code)
at FortuneTeller2.Applet1.getFortunes(Compiled Code)
at FortuneTeller2.Applet1.init(Applet1.java:98)
at sun.applet.AppletPanel.run(Compiled Code)
at
Here is my code that is generating the error (FYI line 98 referenced in the
error above is the line that calls this method. If anyone can help me out I
would greatly appreciate it! Here is the code for the method generating the
errors. (NOTE: I am currently running this applet locally on my PC for a
school project but would like to deploy it to a web site if possible.)
Thanks much, Jen
public void getFortunes() {
try { file = new URL(""+getDocumentBase()+ "fortunes.txt"); }
catch(MalformedURLException e) {}
try { InputStream data = file.openStream(); }
catch(IOException e) {}
BufferedReader input = null;
int fortuneNum, lineNum;
try { input = new BufferedReader(new InputStreamReader(data));
for (fortuneNum = 0; fortuneNum < 24; fortuneNum++)
for(lineNum = 0; lineNum < 4; lineNum++)
fortune[fortuneNum][lineNum] = input.readLine(); }
catch (FileNotFoundException e) {}
catch(IOException e) {}
}
Technical Details
Message-ID:
<924529883.213.23@news.remarQ.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1a6838be51f4fd60,start X-Google-Attributes: gidf74b3,public From: "Jennifer Latham" <jlatham@wnol.net> Subject: File access through applets Date: 1999/04/19 Message-ID: <924529883.213.23@news.remarQ.com> X-Deja-AN: 468299505 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: newsabuse@remarQ.com X-Trace: 924529883.213.23 ZZYOAESJW194F9F8AC usenet1.supernews.com Organization: Posted via RemarQ Communities, Inc. NNTP-Posting-Date: Mon, 19 Apr 1999 13:51:23 GMT Newsgroups: borland.public.jbuilder.java.language