()
| 4660 | } |
| 4661 | |
| 4662 | String openFile() { |
| 4663 | if (writer!=null) { |
| 4664 | interp.error("Currently, only one file can be open at a time"); |
| 4665 | return""; |
| 4666 | } |
| 4667 | String path = getFirstString(); |
| 4668 | String defaultName = null; |
| 4669 | if (interp.nextToken()==')') |
| 4670 | interp.getRightParen(); |
| 4671 | else |
| 4672 | defaultName = getLastString(); |
| 4673 | if (path.equals("") || defaultName!=null) { |
| 4674 | String title = defaultName!=null?path:"openFile"; |
| 4675 | defaultName = defaultName!=null?defaultName:"log.txt"; |
| 4676 | SaveDialog sd = new SaveDialog(title, defaultName, ".txt"); |
| 4677 | if (sd.getFileName()==null) return ""; |
| 4678 | path = sd.getDirectory()+sd.getFileName(); |
| 4679 | } else { |
| 4680 | File file = new File(path); |
| 4681 | if (file.exists() && !(path.endsWith(".txt")||path.endsWith(".java")||path.endsWith(".xls") |
| 4682 | ||path.endsWith(".csv")||path.endsWith(".tsv")||path.endsWith(".ijm") |
| 4683 | ||path.endsWith(".html")||path.endsWith(".htm"))) |
| 4684 | interp.error("File exists and suffix is not '.txt', '.java', etc."); |
| 4685 | } |
| 4686 | try { |
| 4687 | FileOutputStream fos = new FileOutputStream(path); |
| 4688 | BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 4689 | writer = new PrintWriter(bos); |
| 4690 | } |
| 4691 | catch (IOException e) { |
| 4692 | interp.error("File open error \n\""+e.getMessage()+"\"\n"); |
| 4693 | return ""; |
| 4694 | } |
| 4695 | return "~0~"; |
| 4696 | } |
| 4697 | |
| 4698 | String openAsString() { |
| 4699 | String path = getStringArg(); |
no test coverage detected