可以通过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. avalon加载一闪而过现象

      为了避免未经处理的原始模板内容在页面载入时在页面中一闪而过,我们可以使用以下样式(详见这里): .ms-controller,.ms-important,[ms-controller],[ms-i ...

  2. linux route 路由设置小记

    情景一: 有一台ip为172.16.160.53服务器,此服务器为固定ip,由于某些特殊情况,此服务器的ip不能修改. 现在这台服务器需要与另外一个网段ip为172.16.176.150服务器进行局域 ...

  3. 前端开发利器VSCode

    最近找到一款非常好用的开发利器,VSCode.一直认为微软做的东西都很一般,这个软件让我刮目相看了. 之前使用webstorm卡的不行,换了这个非常好用. 用着还不错,这里记录下一些使用的心得. VS ...

  4. C++框架_之Qt的信号和槽的详解

    C++_之Qt的信号和槽的详解 1.概述 信号槽是 Qt 框架引以为豪的机制之一.所谓信号槽,实际就是观察者模式.当某个事件发生之后,比如,按钮检测到自己被点击了一下,它就会发出一个信号(signal ...

  5. Python中如何自定义一个计时器

    import time as t class MyTimer(): # 初始化构造函数 def __init__(self): self.prompt = "未开始计时..." s ...

  6. MacOS下Rails+Nginx+SSL环境的搭建(上)

    这里把主要的步骤写下来,反正我是走了不少弯路,希望由此需求的朋友们别再走类似的弯路.虽说环境是在MacOS下搭建,但是基本上和linux下的很相像,大家可以举一反三. 一.安装Rails 这个是最简单 ...

  7. 【Android应用开发】RecycleView API 翻译 (文档翻译)

    . RecyclerView extends ViewGroupimplements ScrollingView NestedScrollingChild java.lang.Object    ↳ ...

  8. 炫酷:一句代码实现标题栏、导航栏滑动隐藏。ByeBurger库的使用和实现

    本文已授权微信公众号:鸿洋(hongyangAndroid)原创首发. 其实上周五的时候已经发过一篇文章.基本实现了底部导航栏隐藏的效果.但是使用起来可能不是很实用.因为之前我实现的方式是继承了系统的 ...

  9. Redis源码学习:字符串

    Redis源码学习:字符串 1.初识SDS 1.1 SDS定义 Redis定义了一个叫做sdshdr(SDS or simple dynamic string)的数据结构.SDS不仅用于 保存字符串, ...

  10. 【Unity Shader】Unity Chan的卡通材质

    写在前面 时隔两个月我终于来更新博客了,之前一直在学东西,做一些项目,感觉没什么可以分享的就一直没写.本来之前打算写云彩渲染或是Compute Shader的,觉得时间比较长所以打算先写个简单的. 今 ...