01: /*
02: * Created on 03-Jan-2004
03: */
04: package uk.org.ponder.stringutil;
05:
06: /**
07: * @author Bosmon
08: *
09: * The class FilenameUtil contains various useful utility methods for operating on filenames.
10: */
11: public class FilenameUtil {
12: public static final String filesep = System
13: .getProperty("file.separator");
14:
15: public static String getDirectory(String filename) {
16: int lastslashpos = filename.lastIndexOf(filesep);
17: return lastslashpos == -1 ? "" : filename.substring(0,
18: lastslashpos + 1);
19: }
20:
21: public static String getExtension(String filename) {
22: int lastdotpos = filename.lastIndexOf('.');
23: return lastdotpos == -1 ? "" : filename.substring(
24: lastdotpos + 1, filename.length());
25: }
26:
27: /** Return the stem of the supplied filename, containing the portion of the filename
28: * up to the last "." character, or the entire filename if no "." character is
29: * found.
30: * @param filename The filename for which the stem is required.
31: * @return The stem of the filename.
32: */
33: public static String getStem(String filename) {
34: int lastdotpos = filename.lastIndexOf('.');
35: return lastdotpos == -1 ? filename : filename.substring(0,
36: lastdotpos);
37: }
38: }
|