BeanShell bsh Interpreter defaulting file browsing directory to /Applications/ not in the sketch's root/data directory
in
Contributed Library Questions
•
1 year ago
I am using the beanshell interpreter to read a file with code in it to be executed. I assumed that the default directory for file browsing would be the same as it is for the rest of the sketch, however when i run my sketch i get a file not found exception when i use this file path:
- ./code/default-methods/exit.java or
- code/default-methods/exit.java
And i get this as my error telling me that it is actually looking in /Applications/code/default-methods/ for exit.java:
- java.io.FileNotFoundException: /Applications/code/default-methods/exit.java (No such file or directory)
and if i use
- /code/default-methods/exit.java
i then see this:
- java.io.FileNotFoundException: /code/default-methods/exit.java (No such file or directory)
here is the code i am using:
- import bsh.*;
- private Interpreter decoder = new Interpreter();
- //callMethod is called by a class function
- private void callMethod(String method) {
- println(method);
- String file = "/code/default-methods/"+method+".java";
- try {
- decoder.source(file);
- }
- catch (FileNotFoundException fnfe) {
- println("File Not Found:");
- fnfe.printStackTrace();
- }
- catch(IOException ioe) {
- println("IOException:");
- ioe.printStackTrace();
- }
- catch(EvalError err) {
- println("EvalError:");
- err.printStackTrace();
- }
- }
does anyone know why the default directory for file browsing when calling source on the bsh interpreter object would be /Applications/code/ and not /data/code but when i use proxml to save xml files i use ./xml/accounts/accounts.xml to save a file where /code/ and /xml/ are in the same folder, that the default directory is the sketchs data folder?
any help would be greatly appreciated
1