SWT Browser widget: HTML source inside jar?

I want to implement a help system for my small SWT desktop.

I thought of SWT browser widgets containing one html markup page and a set of anchors for navigation (there are very few to explain).

Everything works fine, but how to load an html file from a banner?

I know about getClass().getClassLoader().getResourceAsStream("foo");, but what is the best practice when reading from an input stream? Answer Downloading a resource contained in a bank is discouraged by using FileInputStream.

Thanks in advance

+3
source share
2 answers

Ok, I found a pretty simple solution that obviously just works:

InputStream in = getClass().getClassLoader().getResourceAsStream("html/index.html");
Scanner scanner = new Scanner(in);
StringBuffer buffer = new StringBuffer();
while(scanner.hasNextLine()) {
    buffer.append(scanner.nextLine());
}

browser.setText(buffer.toString());
+5
source

commons-io , , IOUtils.toString(InputStream in); apache;)

commons-io: http://commons.apache.org/io/

apidocs: http://commons.apache.org/io/api-release/index.html

+4

Source: https://habr.com/ru/post/1795248/


All Articles