loadStrings function not as reference?

I’ve just tried the first example on the [loadStrings reference](file:///C:/Programs/Processing/modes/java/reference/loadStrings_.html) page.

It works perfectly loading list.txt from the sketch’s folder, but not from the data folder as stated in the reference. “If the name of the file is used as the parameter, as in the above example, the file must be loaded in the sketch’s “data” directory/folder.”

Am I missing something?

Well, when I use loadStrings(“list.txt”) I always have the file in the data folder so it seems the reference is correct. Maybe it also looks in the sketch folder if the file is not in the data folder?

2 Likes

You can add dataPath("") before the file name when you need it

But it should work without

Maybe show your code

It does work without supplying the dataPath but I just did a quick test and if the file is in the sketch folder, rather than the data folder, loadStrings() still finds it.

2 Likes

Thank you @Chrisir and @PhilHaw for your replies. The code is exactly the example from the loadStrings reference, that’s why I didn’t copy it. I tried this yesterday, went round several times, trying the list.txt alternately in the data folder and the sketch folder. The sketch only read it from the sketch folder. Today it’s reading from either. (PC is W10, frequently updated.) Alright, the help should say something like “it looks for the file first in the data folder and then in the sketch folder”. I think the words “must be loaded in” are unhelpful.

dataPath("") - I’d never heard of that, and it’s not in the reference.

1 Like

Hello @RichardDL,

It works in either folder for me.
I was meticulous testing these seperately.

Here is a tidbit for you:

  println(dataFile(""));
  println(dataPath(""));
  println(dataFile("").getAbsolutePath()); //See the source on GitHub
  
  println(sketchFile("")); 
  println(sketchPath(""));

I found those in the source here:
https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java

:)

1 Like

@glv Yes, thanks. Ignoring the temporary misbehaviour yesterday, my gripe about loadStrings is that it also looks in the sketch folder and that’s different from the documentation.

I have used sketchPath before, didn’t know the others. The three data* functions all give the same thing. The two sketch* ones almost the same as each other (one has \ on the end). None of these 5 is in the documentation.

On the Processing cover page the 5 point is “Well documented”, so why do we have these items that are only published by word of mouth/forum?

2 Likes