[英]Eclipse Plugin: Copy File
i want to copy a file from a folder1 to folder2 in my eclipse project. 我想将文件从Folder1复制到我的Eclipse项目中的folder2。
Here is my code: 这是我的代码:
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject(getSelectedProject().toString());
IFolder folder = project.getFolder("www/GeneratedFiles");
IFolder folder2 = project.getFolder("AppGenerator/TableFiles");
IFile file = folder2.getFile("RelationsBC.bbTable");
System.out.println("FileName: " + file.getName().toString());
if (!project.exists())
project.create(null);
if (!project.isOpen())
project.open(null);
if (!folder.exists()) {
folder.create(true, true, null);
file.copy(folder.getFullPath(), true, null);
} else {
file.copy(folder.getFullPath(), true, null);
}
When I run my Plugin, folder.create(true, true, null)
works fine but file.copy(folder.getFullPath(), true, null);
当我运行插件时, folder.create(true, true, null)
可以正常工作,但file.copy(folder.getFullPath(), true, null);
gives me an error. 给我一个错误。
org.eclipse.core.internal.resources.ResourceException: Resource '/todo/www/GeneratedFiles' already exists.
What I am doing wrong? 我做错了什么? Hope u can understand me fine. 希望你能理解我。
The destination path parameter of copy
should be the name of a file, you are using the name of the folder. copy
的目标路径参数应该是文件名,而您使用的是文件夹名。
Use something like: 使用类似:
IPath path = folder.getFullPath();
path = path.append(file.getName());
file.copy(path, true, null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.