1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-28 09:24:14 +01:00

Save file line by line taking care of OS EOL

Fixes https://github.com/arduino/Arduino/issues/6736
This commit is contained in:
Martino Facchin 2017-10-16 11:33:55 +02:00
parent 31a26cb2fa
commit 3e50aee4cf

View File

@ -907,7 +907,14 @@ public class BaseNoGui {
*/
static public void saveFile(String str, File file) throws IOException {
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
PApplet.saveStrings(temp, new String[] { str });
// Split the file content using minimum common separator \n
// then trim any other character (\r) so saveStrings can print it in the correct
// format for every OS
String strArray[] = str.split("\n");
for (String item : strArray) {
item.trim();
}
PApplet.saveStrings(temp, strArray);
try {
file = file.getCanonicalFile();