Here you can find the source of findDirectoryFromClasspath(Class> cls, String file)
Parameter | Description |
---|---|
cls | The class. |
file | A file inside that directory/. |
public static String findDirectoryFromClasspath(Class<?> cls, String file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.net.URL; public class Main { /**/*w w w . j a v a 2s . c om*/ * Determine a directory's real path from the classpath. * * @param cls The class. * @param file A file inside that directory/. * @return The directory path. */ public static String findDirectoryFromClasspath(Class<?> cls, String file) { URL rootMarker = cls.getResource(file); String markerPath = rootMarker.getPath(); File markerFile = new File(markerPath); return markerFile.getParentFile().getAbsolutePath() + "/"; } }