在Windows 7中按排序顺序移动文件

时间:2014-02-02 16:03:12

标签: java

我通过apache.commons.io移动文件,文件在数组“moveList”中排序。文件排序时e。 G。 a.txt,b.txt,c.txt .... y.txt,z.txt,它们不按此给定顺序移动。我认为windows执行移动过程,这意味着移动的第一个文件不是a.txt,它是中间的一些文件,如n.txt。

您是否知道按我想要的顺序启动移动过程的解决方案? 复制文件没问题,没有移动文件。

    for ( Object o : moveList ) {
        Path p = Paths.get(o.toString());

        String replaceFilePath  = o.toString().replace(movePath.toString(), getTargetPath.toString());     // Tauscht getTargetPath mit movePath     
        File newTargetFile      = Paths.get(replaceFilePath).toFile();                                     

        if (newTargetFile.exists() == false){     
            System.out.println("MOVE : " + p+"    to    "+newTargetFile);
            FileUtils.moveFile(p.toFile(), newTargetFile);       
        }else{}   
    }   

1 个答案:

答案 0 :(得分:0)

如果复制正常,您可以随时使用“复制”和“删除”。虽然这种方法不是最好的方法,但它可能足以解决您的问题......

或许这些可以帮助你...... http://www.mkyong.com/java/how-to-move-file-to-another-directory-in-java/ Move / Copy File Operations in Java