Eclipse 插件:复制文件
Eclipse Plugin: Copy File
我想在我的 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);
我想在我的 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);