http://www.verejava.com/?id=17160016947046
public class Test2 {
public static void main(String[] args)
{
FileUtil.createFile("test2.txt");
FileUtil.renameFile("test2.txt", "newTest2.txt");
FileUtil.deleteFile("newTest2.txt");
}
}
//文件工具封装
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class FileUtil {
//文件的创建
public static boolean createFile(String filePath)
{
File f=new File(filePath);
try {
return f.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
return false;
}
//文件的重命名
public static boolean renameFile(String oldPath,String newPath)
{
File oldFile=new File(oldPath);
return oldFile.renameTo(new File(newPath));
}
//文件的删除
public static boolean deleteFile(String filePath)
{
File f=new File(filePath);
//判断是否是文件 并且存在
if(f.isFile()&&f.exists())
{
return f.delete();
}
return false;
}
}