renameTo作用是文件改名,参数是File类的一个对象,但是这个方法不是一定成功的,有几点需要注意的地方
假如原来的名字为a.txt,需要改名为b.txt,则有如下情况
<span style="white-space:pre"> </span>1. a.txt存在且b.txt不存在的时候renameTo成功
public static void main(String[] args) throws IOException {
File f1 = new File("F:/a.txt");//a.txt已经存在于F盘中
File f2 = new File("F:/b.txt");//b未创建
System.out.println("f1 exists? : " + f1.exists());//f1 exists? : true
System.out.pri......
阅读全文