Opens a file and replaces the text (if any) by the contents of the file.
(String dir, String name)
| 452 | |
| 453 | /** Opens a file and replaces the text (if any) by the contents of the file. */ |
| 454 | public void open(String dir, String name) { |
| 455 | path = dir+name; |
| 456 | File file = new File(path); |
| 457 | if (!file.exists()) { |
| 458 | IJ.error("File not found: "+path); |
| 459 | return; |
| 460 | } |
| 461 | try { |
| 462 | StringBuffer sb = new StringBuffer(5000); |
| 463 | BufferedReader r = new BufferedReader(new FileReader(file)); |
| 464 | while (true) { |
| 465 | String s=r.readLine(); |
| 466 | if (s==null) |
| 467 | break; |
| 468 | else |
| 469 | sb.append(s+"\n"); |
| 470 | } |
| 471 | r.close(); |
| 472 | if (ta!=null && ta.getText().length()>0) { |
| 473 | ta.setText(""); //delete previous contents (if any) |
| 474 | eventCount = 0; |
| 475 | } |
| 476 | create(name, new String(sb)); |
| 477 | changes = false; |
| 478 | } |
| 479 | catch (Exception e) { |
| 480 | IJ.handleException(e); |
| 481 | return; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | public String getText() { |
| 486 | if (ta==null) |