如何以编程方式将文件夹从插件复制到工作空间中的新项目?
我正在开发一个 Eclipse 插件,创建一个新的项目向导。在工作区中创建此类新项目时,我需要它将文件夹及其后代从插件复制到工作区中刚刚创建的项目。问题是,虽然项目是 IResource,但插件文件夹位于文件系统中。
我成功获取了需要复制的源插件文件夹的 URL,并且有 IProject 参考。
我需要知道的是:如何将前者复制到后者中?
I am developing an Eclipse Plugin creating a new Project Wizard. When creating such new project in the workspace I need it to copy a folder, and its descendent, from the plugin to the just created project in the workspace. The problem is that while the project is an IResource
the plugin folder is in the file system.
I succeeded in getting an URL for the source plugin folder I need to copy and I have the IProject reference.
What I need to know is: How to copy the former into the latter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看这个答案,了解如何从插件“中获取”文件/文件夹。
然后在项目中创建新文件/文件夹并使用
InputStream
设置文件内容:Check out this answer to see how to get a file/folder "out of" a plugin.
Then create new files/folders in the projects and set file contents using
InputStream
:如果不确切知道文件,这是不可能的(您无法迭代子文件)。不要使用包含文件和子文件夹的文件夹,而是创建具有该结构的 zip 并将其解压到工作区中(这应该保留所需的结构)。
This is not possible without knowing exactly the files (you cannot iterate over the children). Instead of using a folder with files and subfolders, create a zip with that structure and unpack the zip in your workspace (this should preserve the desired structure).