---
title: "java移动文件"
author: "martinyuan"
date: "2009-09-06T11:19:25Z"
tags: []
slug: "java"
draft: false
lastmod: "2009-09-06T11:19:25Z"
id: 463136
url: "https://martinyuan.iteye.com/blog/463136"
---

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