View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.core.util;
11  
12  import java.io.File;
13  
14  public class FileUtil {
15  
16  
17    public static boolean mustCreateParentDirectories(File file) {
18      File parent = file.getParentFile();
19      if(parent != null && !parent.exists()) {
20        return true;
21      } else {
22        return false;
23      }
24    }
25    
26    public static boolean  createMissingParentDirectories(File file) {
27      File parent = file.getParentFile();
28      if(parent == null || parent.exists()) {
29        throw new IllegalStateException(file + " should not have a null parent");
30      } 
31      if(parent.exists()) {
32        throw new IllegalStateException(file + " should not have existing parent directory");
33      } 
34      return parent.mkdirs();
35    }
36  }