Stream Tokenizer

[nobr]sir

i am using a text file i want to insert an html content breaks i.e

at every end of the line

but by stream tokenizer i was able to find out numeric values,end of the line,end of the file,and string values.but the thing is i was not able to find out the occurance of the special characters i was able to find the occurance but dosent know hoe to write the special characters

i am sending my code please look after to it

String fileName ="ser.txt";

Reader fileReader =new FileReader (fileName);

StreamTokenizer tokenizer =new StreamTokenizer (fileReader);

fileName ="ser1.txt";

Writer fileWriter =new FileWriter (fileName);

PrintWriter fileOut =new PrintWriter (fileWriter);

tokenizer.eolIsSignificant (true);

while (StreamTokenizer.TT_EOF != tokenizer.nextToken ())

{

if (StreamTokenizer.TT_NUMBER == tokenizer.ttype)

{

int i=(int)tokenizer.nval;

if(i>15000)

{

fileOut.print(i);

fileOut.print(i);

}

}

if (StreamTokenizer.TT_WORD == tokenizer.ttype)

{

String ui=tokenizer.sval;

if(ui.equals("UniSTS"))

{

System.out.println("reached here");

}

fileOut.print (tokenizer.sval+" ");

}

if (StreamTokenizer.TT_EOL == tokenizer.ttype)

{

fileOut.println("<br>");

}

else

{

fileOut.print()

//how to print

}

[/nobr]

[2482 byte] By [nagaraja] at [2007-10-2 22:00:39]
# 1

If I'am getting you right you want to insert <br> for a linefeed in a text you read from file.

If so simply do the following:

- read the whole text from the File into a string, with BufferedReader and FileReader

- use the replaceAll() Method of String to replace all linefeeds with <br>

erik44a at 2007-7-14 1:16:53 > top of Java-index,Core,Core APIs...