//文件原地址
File oldFile = new File("c:/test.xls");
//文件新(目标)地址
String newPath = "c:/test/";
//new一个新文件夹
File fnewpath = new File(newPath);
//判断文件夹是否存在
if(!fnewpath.exists())
fnewpath.mkdirs();
//将文件移到新文件里
File fnew = new File(newPath +oldFile.getName());
oldFile.renameTo(fnew);
File oldFile = new File("c:/test.xls");
//文件新(目标)地址
String newPath = "c:/test/";
//new一个新文件夹
File fnewpath = new File(newPath);
//判断文件夹是否存在
if(!fnewpath.exists())
fnewpath.mkdirs();
//将文件移到新文件里
File fnew = new File(newPath +oldFile.getName());
oldFile.renameTo(fnew);
本文提供了一个使用Java进行文件移动的简单示例。通过创建文件和文件夹,并利用renameTo方法实现文件从一个目录到另一个目录的移动。适用于初学者了解基本的文件操作。
1286

被折叠的 条评论
为什么被折叠?



