servlet-null error

hey

i dnt no if any1 can help me?

i wrote a servlet which basically opens an random access file and dispalys the content of the file on a web page.

when i run its given me no errors but on the web page its keep saying null...

i dnt really no why its doing it.

here is the code..

File name = new File("c:/resin-2.1.5/doc/meng/database.txt");

if(name.exists())

{

try

{

RandomAccessFile r =new RandomAccessFile(name, "r");

String text=null;

while((text=r.readLine()) != null)

System.out.println(text);

out.println( text + "\n");

}

catch(IOException e2)

{}

}

when i did system.out.println(text) as you can see i can see the content of the file on my console but its not dispalying it on the web page

thanks

[848 byte] By [gansta007a] at [2007-9-28 9:49:26]
# 1

[nobr]You have a semantic error in the following lines:

String text=null;

while((text=r.readLine()) != null)

System.out.println(text);

out.println( text + "\n");

You are doing only a System.out.println for all lines. Not an out.println! Change your code like this:

String text=null;

while((text=r.readLine()) != null)

{ // Put a curly brace: More than one line in loop!

System.out.println(text);

out.println( text + "<br>");

}

Additionally, try formatting your output to HTML.

1. Enclose the output between <HTML><BODY> and </BODY></HTML> tags.

2. \n does not work for HTML. Replace \n with

.[/nobr]

jay_ramanathana at 2007-7-11 23:18:14 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...