[2631] in java-interest
file-reading in java
daemon@ATHENA.MIT.EDU (Tim Moons)
Sat Oct 7 11:36:15 1995
Date: Sat, 7 Oct 1995 14:06:49 +0100
To: java-interest@java.sun.com
From: tim@nic.INbe.net (Tim Moons)
Hello everybody,
I hava a read file problem.
My problem :
I try to read the contents from the textfile 'INPUT.txt' into the
string-variable 'text', so I can use this text in my applet.
When I put my applet in a HTML-page and I call up this page in HOTjava, the
applet is loaded but there shows up a Frame with the title :
'ACCESS EXCEPTION'
and the exception-text :
'an applet attempted to read INPUT.txt' .
I putted the file 'INPUT.txt' in my classes directory.
I'm working on WIN95.
My problem : I have to give at monday a little java-demo at the company, and
I really need this read-from-harddisk facility.
I'm already searching more as a week on this problem and it becomes a little
bit "hot under my ass" (you know what I mean ???)
If you don't understand my program, can someone just give me an example from
how to read a text file ??????
The program that gives the problem :
/* PROGRAM START*/
import browser.Applet;
import awt.*;
import java.util.Date;
import java.io.*;
import java.lang.String;
class reading extends Applet implements DialogHandler {
Font dialogFont;
static String text="text at the beginning";
static int teller=1;
public void init() {
resize(500,150);
dialogFont= getFont("DialogInput", Font.PLAIN, 12);
}
public void paint(Graphics g) {
String hulp, Suur, Smin;
Date date=new Date();
int uur,min;
uur=date.getHours(); min=date.getMinutes();
if (uur-1<10) {
Suur="0" + String.valueOf(uur-1);
}
else {
Suur=String.valueOf(uur-1);
}
if (min<10) {
Smin="0" + String.valueOf(min);
}
else {
Smin=String.valueOf(min);
}
g.setForeground(Color.white);
g.paint3DRect(0,0,500,150,true,false);
g.setForeground(Color.black);
g.drawString(text,5,15);
g.drawString(Suur + ":" + Smin,240,50);
if (teller==1) {
teller++;
write();
}
}
public void write() {
String filename="INPUT.txt";
File file;
FileInputStream Finstream;
try {
file=new File(filename);
Finstream=new FileInputStream(file);
} catch (Exception e) {
text="There is something wrong !!!!!!!";
if (teller==1) {
repaint();
}
return;
}
DataInputStream dis=new DataInputStream(Finstream);
text=dis.readLine();
while(text.length() != -1) {
repaint();
text=dis.readLine();
}
Finstream.close();
}
}
/*PROGRAM END*/
I realy thank you in advance.......
Tim Moons :-)
Email : tim@innet.be
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com