我想将文件从我的 Eclipse 项目中的folder1复制到folder2。
这是我的代码:
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);
}
当我运行插件时,folder.create(true, true, null)
工作正常,但 file.copy(folder.getFullPath(), true, null);
给我一个错误。
org.eclipse.core.internal.resources.ResourceException: Resource '/todo/www/GeneratedFiles' already exists.
我做错了什么?希望你能理解我。
最佳答案
copy
的目标路径参数应该是文件的名称,您使用的是文件夹的名称。
使用类似的东西:
IPath path = folder.getFullPath();
path = path.append(file.getName());
file.copy(path, true, null);
关于java - Eclipse插件: Copy File,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33010029/