A resource finder encapsulates access to the ResourceLoader class in the OSP library, allowing easy access to files in the JAR file of the simulation, on the applet server, or anywhere else in the file path.
Files located by resource finder can provide any type of data, though some types, like text, images, and audio, can be quickly read using particular convenience methods.
To add a resource finder element to your model, drag the icon element to the list of your model elements and set the "File to read" field to a file in your hard disk (under your simulation directory) or link it to a String model variable (as in %myModelString%).
You can also leave the "File to read" field empty and then use convenience methods provided by the element which accept a particular file path.
A call to any of the element's convenience methods will attempt to read the file and return the data requested, if successful, or null if it failed to do so.
The most popular convenience methods are the following:
Next methods provide direct access to reading objects, which will allow you to read directly from the file, in any suitable format:
All these convenience methods have a variant that allows reading a particular file (different from the one specified in the "File to read" field). As, for example, String getString(String path).
The element uses the OSP core class ResourceLoader. Additional configuration capabilities are possible addressing directly the static methods of this class.
String content = resourceFinder.getString(); if (content==null) { _println("Could not read text from file: "+resourceFinder.getFilename()); return; } // Now, do whatever you want with the content _println("Text read from file: "+resourceFinder.getFilename()); _println (content);