public static void main(String[] args) { List<Object> list = new ArrayList<>(); File file1 = new File("d:\\ti.txt"); File file2 = new File("d:\\titi.txt"); file1.renameTo(file2); list.add(file1); list.add(file2); for(int i = 0;i<list.size();i++){ File f = (File)list.get(i); f.renameTo(new File("e:\\"+i+"cc.txt")); System.out.println(i); } }
renameTo只要改变地址就可以了,不仅重命名还可以移动,记住d盘中有ti.txt和titi.txt才可以移动哦
时间: 2024-10-14 12:42:11