How do I get the content from an asset loaded with the extension?

Thanks to everyone for all their suggestions, after much searching and testing, finally came up with this solution, which works for a text content file:

@SimpleFunction(description = "Reads the contents of a file in the extension's assets and return it as a string")
  public String ReadAssetFile() {
    final StringBuilder sb = new StringBuilder();

    try {
      final InputStream is = form.openAssetForExtension(this, "myStyleSheet.css");  //name of file here
      int character = is.read();
      while (character != -1) {
        sb.append((char) character);
        character = is.read();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    return sb.toString();
  }
8 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.