簡體   English   中英

Eclipse中項目文件的絕對路徑

[英]Absolute Path of project file in eclipse

我想在eclipse插件中打印文件rep.xml的絕對路徑。

我已將文件rep.xml放在路徑下
C:\\Program Files\\Eclipse\\Documents\\Eclipse\\samplePlugin\\resources\\rep.xml.

我嘗試使用file.getLocation()打印它。
它返回C:/Program Files/eclipse/Documents/runtime-EclipseApplication

如何在Eclipse中打印絕對路徑。 請幫忙。

如果您想讀取插件中包含的文件,請使用以下命令:

Bundle bundle = Platform.getBundle("your plugin id");

URL url = FileLocator.find(bundle, new Path("path relative to the plugin"), null);

URL fileUrl = FileLocator.toFileURL(url);

File file = new File(fileUrl.getFile());

... read file using normal Java file APIs

您還可以使用FrameworkUtil來獲取捆綁包,從而避免對插件ID進行硬編碼:

Bundle bundle = FrameworkUtil.getBundle(getClass());

給您包含給定類的Bundle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM