Java tutorial
/* * Copyright(C) 2010-2013 Baidu Group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ package com.baidu.terminator.manager.common.file; import java.io.File; import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class FileUtils { private static final Log LOGGER = LogFactory.getLog(FileUtils.class); public static void createFile(String fileLocation) { File file = new File(fileLocation); File parentFile = file.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { LOGGER.error("create file :" + fileLocation + " fail!"); } } } }