StringTokenizer converted my escape characters

I am using messages from a script file, read by StringTokenizer. They look like this

"Welcome to this game\nThis is the second line of the message.\nThis is the third line.

Problem is the \n will be printed converted into characters so when I use it in game i get all the text with “\n” also printed on screen instead of doing the next line command. I tried creating a StringTokenizer with delimiter but failed, how do I fix it?

the string i read from my script, i have tried manipulating it with mess=mess.replaceAll("\n", “\n”); to somehow get back my escape characters but I get no way of getting thr “\n” functionality of skipping a line instead of just typing the 2 characters on screen ???

This works just fine for me

public static void main(String… args){
String str = “Welcome to this game\nThis is the second line of the message.\nThis is the third line”;

	StringTokenizer tokenizer = new StringTokenizer(str, "\n");
	while(tokenizer.hasMoreTokens()){
		System.out.println(tokenizer.nextToken());
	}
	
}

Output:
Welcome to this game
This is the second line of the message.
This is the third line

it works for me too when reading from a String in my code, but not when i stuff that text in a txt file and read from it using

this.stringTokenizer = new StringTokenizer(this.inFile.readLine());


while(this.stringTokenizer.hasMoreTokens())
tmp.add(this.stringTokenizer.nextToken());

It does not interpret the \n as escape characters anymore. So, the readline must be the fault, maybe i should read it differently?

That’s because \ is an escape character in java, but not in a text file.
In a text file, ‘\n’ is just that, 2 characters, so they will be read as 2 characters.
Why don’t you just use ‘enters’ in your text file?

Yes that did the trick, thanks.