ITeye博客

java移动文件

martinyuan · 2009-09-06 11:19 · java · Markdown

//文件原地址
  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);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。