@@ -162,12 +162,11 @@ static public String loadFile(File file) throws IOException {
162162 * Spew the contents of a String object out to a file. As of 3.0 beta 2,
163163 * this will replace and write \r\n for newlines on Windows.
164164 * https://github.com/processing/processing/issues/3455
165+ * As of 3.3.7, this puts a newline at the end of the file,
166+ * per good practice/POSIX: https://stackoverflow.com/a/729795
165167 */
166- static public void saveFile (String str , File file ) throws IOException {
167- if (Platform .isWindows ()) {
168- String [] lines = str .split ("\\ r?\\ n" );
169- str = PApplet .join (lines , "\r \n " );
170- }
168+ static public void saveFile (String text , File file ) throws IOException {
169+ String [] lines = text .split ("\\ r?\\ n" );
171170 File temp = File .createTempFile (file .getName (), null , file .getParentFile ());
172171 try {
173172 // fix from cjwant to prevent symlinks from being destroyed.
@@ -178,9 +177,11 @@ static public void saveFile(String str, File file) throws IOException {
178177 throw new IOException ("Could not resolve canonical representation of " +
179178 file .getAbsolutePath ());
180179 }
181- // Can't use saveStrings() here b/c Windows will add a ^M to the file
180+ // Could use saveStrings(), but the we wouldn't be able to checkError()
182181 PrintWriter writer = PApplet .createWriter (temp );
183- writer .print (str );
182+ for (String line : lines ) {
183+ writer .println (line );
184+ }
184185 boolean error = writer .checkError (); // calls flush()
185186 writer .close (); // attempt to close regardless
186187 if (error ) {
0 commit comments