Load this piece of code from a file.
()
| 281 | * Load this piece of code from a file. |
| 282 | */ |
| 283 | public void load() throws IOException { |
| 284 | program = Util.loadFile(file); |
| 285 | |
| 286 | if (program == null) { |
| 287 | System.err.println("There was a problem loading " + file); |
| 288 | System.err.println("This may happen because you don't have permissions to read the file, or the file has gone missing."); |
| 289 | throw new IOException("Cannot read or access " + file); |
| 290 | } |
| 291 | |
| 292 | // Remove NUL characters because they'll cause problems, |
| 293 | // and their presence is very difficult to debug. |
| 294 | // https://github.com/processing/processing/issues/1973 |
| 295 | if (program.indexOf('\0') != -1) { |
| 296 | program = program.replaceAll("\0", ""); |
| 297 | } |
| 298 | savedProgram = program; |
| 299 | |
| 300 | // This used to be the "Fix Encoding and Reload" warning, but since that |
| 301 | // tool has been removed, let's ramble about text editors and encodings. |
| 302 | if (program.indexOf('\uFFFD') != -1) { |
| 303 | System.err.println(file.getName() + " contains unrecognized characters."); |
| 304 | System.err.println("You should re-open " + file.getName() + |
| 305 | " with a text editor,"); |
| 306 | System.err.println("and re-save it in UTF-8 format. Otherwise, you can"); |
| 307 | System.err.println("delete the bad characters to get rid of this warning."); |
| 308 | System.err.println(); |
| 309 | } |
| 310 | |
| 311 | setLastModified(); |
| 312 | setModified(false); |
| 313 | } |
| 314 | |
| 315 | |
| 316 | /** |
no test coverage detected