How do I get rid of all line breaks when I read a text file in Java?
String text = readFileAsString("textfile.txt");
text.replace("\n", "");
I tried it like this, but it didn't work.
string java newline line-breaks
First of all, you have to substitute the result of text.replace into text again.
String text = readFileAsString("textfile.txt");
text = text.replace("\n", "").replace("\r", "");
This is how it should be done.
© 2024 OneMinuteCode. All rights reserved.