请问各位!怎么重命名文件夹,我用了renameTo(),结果是生成了一个新文件夹,原来的还在!
附上代码/**
 * 重命名文件
 * @param oldName
 * @param newName
 * @param path
 * @return
 */
public static boolean renameFile(String oldName,String newName,String path){
File oldFile = new File(path+"/"+oldName);
File newFile = new File(path+"/"+newName);
     if(oldFile.exists()){
     if(!newFile.exists()){
     if(oldFile.renameTo(newFile)){
     return true;
     }else{
     return false;
     }
     }else{
     return false;
     }
     }else{
     return createFolder(newName,path);
     }
}

解决方案 »

  1.   

    test通过你在
    return createFolder(newName,path);
    前面加一句
    System.out.println("Create new");你测的时候,肯定一直走的这里
      

  2.   

    你把path+"/"+oldName打印出来看看和你放文件的路径是否一致
      

  3.   

    1楼的:没有走return createFolder(newName,path)分支
    2楼的:路径一致
      

  4.   

    你最好换个简单的文件夹试试看,rename本身应该不会产生这种问题,而且你的函数在我这边是好的
    所以,应该可以排除程序的错
    renameFile("temp1", "temp2", "c:");