可以通过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.
相关文章
- 利用Python从文件中读取字符串(解决乱码问题)
- python输出字典中的值_Python:从文件的输出中读取值并将其解释为字典中的键值...
- Java读取jar包中的resource资源文件
- 从Excel文件中读取数据
- 在Spring-boot中,为@Value注解添加从数据库读取properties支持
- Android动态部署五:怎样从插件apk中启动Service
- 使用Flink时从Kafka中读取Array[Byte]类型的Schema
- C# 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。
- 从SQL查询分析器中读取EXCEL中的内容
- webpack打包vue项目,资源路径如何从绝对路径改为相对路径?css中的图片资源如何修改配置?