SWT Browser小部件:jar里面的html源码? [英] SWT Browser widget: html source inside jar?

查看:118
本文介绍了SWT Browser小部件:jar里面的html源码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的小型SWT桌面应用程序实现一个帮助系统。

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

我考虑过一个包含单个html标记页面和一个集合的SWT浏览器小部件导航的锚点(只有很少的东西需要解释)。

I've thought about a SWT browser widget containing a single html markup page and a set of anchors to navigate (there are only very few things to explain).

一切正常,但如何从jar加载html文件?

Everything works fine, but how do I load the html file from a jar?

我知道 getClass()。getClassLoader()。getResourceAsStream(foo); ,但是什么是最佳做法从输入流中读取? 加载包含在jar中的资源的答案劝阻使用a FileInputStream

I know aboutgetClass().getClassLoader().getResourceAsStream("foo");, but what is the best practice when reading from the input stream? The answer to Load a resource contained in a jar dissuades using a FileInputStream.

提前致谢

推荐答案

好吧,我找到了一个相当简单的解决方案,显然只是起作用:

Well, I found a rather 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());

这篇关于SWT Browser小部件:jar里面的html源码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆