可以通过Eclipse里的OSGi的Bundle类,获取插件目录下的某个文件的输入流:

1. Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);   

2. URL url = bundle.getResource("/icon/xx.txt");   

3. InputStream is = FileLocator.toFileURL(url).openStream();  



从Bundle查找资源:

Bundle bundle = Platform.getBundle(pluginId);

URL fullpathString = BundleUtility.find(bundle, filePath);



Enumeration org.osgi.framework.Bundle.findEntries(String path, String filePattern, boolean recurse)

Returns entries in this bundle and its attached fragments. This bundle's

class loader is not used to search for entries. Only the contents of this bundle

and its attached fragments are searched for the specified entries. If this

bundle's state is INSTALLED, this method must attempt to resolve

this bundle before attempting to find entries.



This method is intended to be used to obtain configuration, setup,

localization and other information from this bundle. This method takes into

account that the "contents" of this bundle can be extended with fragments. This

"bundle space" is not a namespace with unique members; the same entry name can

be present multiple times. This method therefore returns an enumeration of URL

objects. These URLs can come from different JARs but have the same path name.

This method can either return only entries in the specified path or recurse into

subdirectories returning entries in the directory tree beginning at the

specified path. Fragments can be attached after this bundle is resolved,

possibly changing the set of URLs returned by this method. If this bundle is not

resolved, only the entries in the JAR file of this bundle are returned.



Examples:  // List all XML files in the OSGI-INF directory and below

 Enumeration e = b.findEntries("OSGI-INF", "*.xml", true);

 

 // Find a specific localization file

 Enumeration e = b

         .findEntries("OSGI-INF/l10n", "bundle_nl_DU.properties", false);

 if (e.hasMoreElements())

     return (URL) e.nextElement();

 

Note: Jar and zip files are not required to include directory entries. URLs to directory entries will not be returned if the bundle contents do not contain directory entries. Parameters: path The path name in which to look. The path is always relative to the
root of this bundle and may begin with "/". A path value of "/" indicates the root of this bundle. filePattern The file name pattern for selecting entries in the specified path. The pattern is only matched against the last element of the entry path. If the
entry is a directory then the trailing "/" is not used for pattern matching. Substring matching is supported, as specified in the Filter specification, using the wildcard character ("*"). If null is specified, this is equivalent to "*" and matches all files.
recurse If true, recurse into subdirectories. Otherwise only return entries from the specified path. Returns: An enumeration of URL objects for each matching entry, or null if an entry could not be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE],
and the Java Runtime Environment supports permissions. The URLs are sorted such that entries from this bundle are returned first followed by the entries from attached fragments in ascending bundle id order. If this bundle is a fragment, then only matching
entries in this fragment are returned.

从Eclipse插件中读取资源的更多相关文章

  1. java 从jar包中读取资源文件

    在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...

  2. (转)java 从jar包中读取资源文件

    (转)java 从jar包中读取资源文件 博客分类: java   源自:http://blog.csdn.net/b_h_l/article/details/7767829 在代码中读取一些资源文件 ...

  3. 深入jar包:从jar包中读取资源文件getResourceAsStream

    一.背景 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等). 在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不 ...

  4. 【解惑】深入jar包:从jar包中读取资源文件

    [解惑]深入jar包:从jar包中读取资源文件 http://hxraid.iteye.com/blog/483115 TransferData组件的spring配置文件路径:/D:/develop/ ...

  5. 2018-10-10 在浏览器插件中读取JSON资源文件

    续前文: 浏览器插件实现GitHub代码翻译原型演示 此改进只为演示: 词典数据提取到json文件 · program-in-chinese/webextension_github_code_tran ...

  6. [Java基础] 深入jar包:从jar包中读取资源文件

    转载: http://hxraid.iteye.com/blog/483115?page=3#comments 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等).在单独运行的时候这些简单的 ...

  7. 深入jar包:从jar包中读取资源文件

    我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等).在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不出来了.看看 ...

  8. Java/JavaWeb中读取资源文件

    1.一般工程中使用I/O类指定文件的绝对路径读取 FileInputStream fis = new FileInputStream("src/main/resources/zsm.prop ...

  9. 从jar中读取资源文件的问题

    在项目中遇到了一个问题,在IDE中读取配置文件的程序,打成架包以后,放到服务器上跑,报找不到资源文件的错误. 其中,资源文件的路径如下: 获取配置文件路径和读取的方法如下: private stati ...

随机推荐

  1. C语言程序设计第三次作业——选择结构(1)

    一.改错题 1.题目计算f(x)的值:输入实数x,计算并输出下列分段函数f(x)的值,输出时保留1位小数. 源程序(有错误的程序): #include <stdio.h> int main ...

  2. SpringMVC中url-pattern /和/*的区别

    http://blog.csdn.net/u010648555/article/details/51612030

  3. RESTful Console Application

    RESTful Console Application Introduction Inspirited by RESTFul architecture, A console application t ...

  4. 一个页面从输入url到页面加载显示完成,中间都经历了什么

    第一种解释: 一般会经历以下几个过程: 1.首先,在浏览器地址栏中输入url 2.浏览器先查看浏览器缓存-系统缓存-路由器缓存,如果缓存中有,会直接在屏幕中显示页面内容.若没有,则跳到第三步操作. 3 ...

  5. 【vuejs深入三】vue源码解析之二 htmlParse解析器的实现

    写在前面 一个好的架构需要经过血与火的历练,一个好的工程师需要经过无数项目的摧残. 昨天博主分析了一下在vue中,最为基础核心的api,parse函数,它的作用是将vue的模板字符串转换成ast,从而 ...

  6. 吴恩达深度学习第1课第4周-任意层人工神经网络(Artificial Neural Network,即ANN)(向量化)手写推导过程(我觉得已经很详细了)

    学习了吴恩达老师深度学习工程师第一门课,受益匪浅,尤其是吴老师所用的符号系统,准确且易区分. 遵循吴老师的符号系统,我对任意层神经网络模型进行了详细的推导,形成笔记. 有人说推导任意层MLP很容易,我 ...

  7. 嫌我的键盘的backspace太小,就尝试了一下改键工具--keyTweak

    KeyTweak是一个很简单的键盘remap小工具,主要功能就是可以让我们选择某个按键并重新赋予该按键一个新的功能.如果哪天你的键盘某个重要的键坏掉了,可以通过这个免费的软件来重新定义该按键的功能.譬 ...

  8. PHP 5 Calendar 函数

    PHP Calendar 简介 日历扩展包含了简化不同日历格式间的转换的函数. 它是基于 Julian Day Count(儒略日计数),是从公元前 4713 年 1 月 1 日开始计算的. 注释:如 ...

  9. Java语言程序设计-Markdown格式作业模板

    Markdown格式作业模板如下,大家可以直接复制粘贴使用. 注意:作业中不能只写答案,题目本身也要出现.. # 1. 本章学习总结 你对于本章知识的学习总结 # 2. 书面作业 **Q1 java ...

  10. Windows下使用Vim极简入门

    0.下载与安装 在vim官网下载 1.Vim常见的几种模式: 一般模式:主要用于浏览,不能随意删除.修改等.按Esc进入该模式. 插入模式:类似平常我们打开记事本后所在的模式.在命令模式下按i进入. ...