Here you can find the source of createDirsForFile(File file)
Parameter | Description |
---|---|
file | the file containing possibly non-existent directories |
public static void createDirsForFile(File file) throws IOException
/*// www . ja va2 s . c o m Copyright 1996-2008 Ariba, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. $Id: //ariba/platform/util/core/ariba/util/core/FileUtil.java#24 $ */ import ariba.util.log.Log; import java.io.File; import java.io.IOException; import java.io.FileFilter; import java.io.FilenameFilter; import java.util.Random; import java.util.List; public class Main{ /** Create directories for file if they do not exist. @param file the file containing possibly non-existent directories @exception IOException if there was an error finding or creating the directory @aribaapi documented */ public static void createDirsForFile(File file) throws IOException { File dir = file.getParentFile(); if (dir != null) { directory(dir); } } /** Returns the File for a named directory. If there is no directory <B>dir</B> relative to the File <B>base</B>, it and all needed parent directories will be created. @param base the parent directory of <b>dir</b> @param dir the name of the directory to find or create @return the directory found or created @exception IOException if there was an error finding or creating the directory @aribaapi documented */ public static File directory(File base, String dir) throws IOException { return directory(base.getPath(), dir); } /** Returns the File for a named directory. If there is no directory <B>dir</B> relative to the directory <B>base</B>, it and all needed parent directories will be created. @param base the parent directory of <b>dir</b> @param dir the name of the directory to find or create @return the directory found or created @exception IOException if there was an error finding or creating the directory @aribaapi documented */ public static File directory(String base, String dir) throws IOException { return directory(new File(new File(base), dir)); } /** Returns the File for a named directory. If there is no directory it and all needed parent directories will be created. @param dir the name of the directory to find or create @return the directory found or created @exception IOException if there was an error finding or creating the directory @aribaapi documented */ public static File directory(String dir) throws IOException { return directory(new File(dir)); } /** Returns the File for a directory. If there is no directory it and all needed parent directories will be created. @param dir the directory to find or create @return the directory found or created @exception IOException if there was an error finding or creating the directory @aribaapi documented */ public static File directory(File dir) throws IOException { if (!dir.exists()) { if (!dir.mkdirs()) { throw new IOException(Fmt.S("can't create directory %s", dir)); } } if (!dir.isDirectory()) { throw new IOException(Fmt.S("%s is not a directory", dir)); } return dir; } }