I have a Reader reading in a file to edit it and save it afterwards with a printwriter. The start input is like this The problem is, that sometimes whitespaces are mistaken for new lines somehow like here. I goes even further in cutting it again after the first time like this
I have tried some different split characters, like
(what it actually is (you can see in System.out.println)) but I can´t get it to work properly
The Original loaded Textfile is this and the output of the getText is this
if (lastClicked != 0) {
String path;
switch (lastClicked) {
case 1:
path = "data/alyxia_status.got";
break;
case 2:
path = "data/mog_status.got";
break;
case 3:
path = "data/telias_status.got";
break;
default:
path = "data/tiernen_status.got";
}
String text = textPane.getText();
String toWrite = text.substring(44, text.length() - 16);
System.out.println(toWrite);
String[] parts = toWrite.split("<br>");
FileWriter fileWriter;
try {
fileWriter = new FileWriter(path);
PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.print(parts[0]);
for (int i = 1; i<parts.length; i++) {
if (parts[i] != "" && parts[i] != " ") {
printWriter.println();
printWriter.print(parts[i]);
}
}
printWriter.close();
} catch (IOException e1) {
e1.printStackTrace();
System.err.println("Saving failed");
}
}//end if
It should just split on the string "<br>"
and not on white spaces that are in between (in System.out.println it´s showing "Base" and then in a newline "Damage")