1 /*******************************************************************************
2 * Copyright (c) 2009 Ordina and committers to Mod4j
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ordina - initial implementation
10 *******************************************************************************/
11 package org.mod4j.dslcommon.io;
12
13 import java.net.URL;
14
15 public class Files {
16
17 /**
18 * Try to find a file on the CLASSPATH
19 *
20 * @param filename
21 * The file to find, relatrive path to the CLASSPATH
22 * @return If found, the URL of the file, otherwise null
23 */
24 public static String findFile(String filename) {
25 Files f = new Files();
26 return f.getDir(filename);
27 }
28
29 /**
30 * Try to find a file on the CLASSPATH
31 *
32 * @param filename
33 * The file to find
34 * @return If found, the URL of the file, otherwise null
35 */
36 public String getDir(String filename) {
37 ClassLoader cls = this.getClass().getClassLoader();
38 URL url = cls.getResource(filename);
39 if (url == null) {
40 System.err.println("File [" + filename + "] not found");
41 return null;
42 }
43 filename = url.toString();
44 return filename;
45 }
46 }