1 package org.apache.texen.util;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23
24 /**
25 * A general file utility for use in the context
26 *
27 * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
28 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
29 * @version $Id: FileUtil.java 525422 2007-04-04 05:54:17Z wglass $
30 */
31 public class FileUtil
32 {
33 /**
34 * Creates the directory s (and any parent directories needed).
35 *
36 * @param s path/directory to create.
37 * @return report of path/directory creation.
38 */
39 static public String mkdir (String s)
40 {
41 try
42 {
43 if ((new File(s)).mkdirs())
44 return "Created dir: "+s;
45 else
46 return "Failed to create dir or dir already exists: "+s;
47 }
48 catch (Exception e)
49 {
50 return e.toString();
51 }
52 }
53
54 /**
55 * A method to get a File object.
56 *
57 * @param s path to file object to create.
58 * @return File created file object.
59 */
60 public static File file(String s)
61 {
62 File f = new File(s);
63 return f;
64 }
65
66 /**
67 * A method to get a File object.
68 *
69 * @param base base path
70 * @param s file name
71 * @return File created file object.
72 */
73 public static File file(String base, String s)
74 {
75 File f = new File(base, s);
76 return f;
77 }
78 }