繁体   English   中英

Eclipse插件:复制文件

[英]Eclipse Plugin: Copy File

我想将文件从Folder1复制到我的Eclipse项目中的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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM