I'm trying to read a file on the same system as the applet and display it in an applet window. my problem is the file which includes line breaks displays on one line. how can i fix this???
datafile.txt
Code:
import java.applet.Applet;
import java.awt.Graphics;
import java.io.*;
public class Simple extends Applet {
StringBuffer buffer;
public void init() {
buffer = new StringBuffer();
readTextFromJar("datafile.txt");
}
public void readTextFromJar(String s) {
String thisLine;
try {
InputStream is = getClass().getResourceAsStream(s);
BufferedReader br = new BufferedReader
(new InputStreamReader(is));
while ((thisLine = br.readLine()) != null) {
System.out.println(thisLine);
buffer.append(thisLine);
repaint();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawRect(0, 0, size().width - 1, size().height - 1);
g.drawString(buffer.toString(), 5, 20);
}
}
datafile.txt
Code:
line1
line2
line3