请问各位!怎么重命名文件夹,我用了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);
}
}
附上代码/**
* 重命名文件
* @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);
}
}
解决方案 »
- 关于Java Gui编程
- 怎么格式化数字成字符串,不足长度被0
- 在table的cell中处理checkbox,CellRenderer和CellEditor怎么协同工作?
- 类型不匹配:不能从 String 转换为 Enumeration
- 时间问题求解
- package问题
- List对象获取对象属性值最大的对象
- java中如何表示不可打印字符?
- 100分!帮忙找错误!
- 急问题:showMessageDialog编译时总说“不兼容的类型”,换成showInputDialog就可以
- 俄罗斯方块方块更新以及落下固定的问题,跪求各位高手给解决一下,小弟毕业设计,马上答辩!很急急急急急啊
- 共500分!!!Java awt 如何将输出到屏幕上的图像输出到图片 如果有好思路另开帖子另给分
return createFolder(newName,path);
前面加一句
System.out.println("Create new");你测的时候,肯定一直走的这里
2楼的:路径一致
所以,应该可以排除程序的错
renameFile("temp1", "temp2", "c:");