We are about to switch to a new forum software. Until then we have removed the registration on this forum.
What I am wanting is that when the user presses a button they will then be prompted to select a file to use as an input. The code I have works fine on Java mode but when I try it on OpenProcessing nothing happens when I press the button.
void keyTyped()
{
if (key == 'p')
{
selectInput("Select the file you wish to use:", "fileSelected");
}
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
arrayString = loadStrings(selection.getAbsolutePath());
for (int i = 0; i < arrayString.length; i = i + 1)
{
String[] info = split(arrayString[i], '_');
arrayString[i] = info[0];
minimum[i] = int(info[1]);
maximum[i] = int(info[2]);
}
}
}
Answers
You don't say whether you are using Java or JavaScript mode but the most probable cause is a security exception. A program running on a web server is not allowed access to the local file system.
Which mode are you using?
I was using JavaScript mode.
Ooops :\"> had I looked at the forum section it would have been obvious.
I am not sure about access restrictions in JavaScript mode although I am aware that it can be different if the script is run from the local machine or from a remote server; and even this is dependent on the browser.
Perhaps someone else can give you a more definitive answer.
Yes, to my knowledge, a JS script cannot read a local file, unless it is served by the same server (than the one delivering the script).