io.github.yangkeith.utils.SourceUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils Show documentation
Show all versions of utils Show documentation
A tool class that I use myself
The newest version!
package io.github.yangkeith.utils;
import io.github.yangkeith.validate.BaseValidate;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
/**
* @program: KeithUtils
* @package: io.github.yangkeith.utils
* @description:
* @author: Keith
* @date:Created in 2022-08-29 15:11
*/
public class SourceUtil {
static {
new BaseValidate();
}
public static URL getSourceDir() {
return getResource("");
}
public static String getPackageName(URL sourceDir) {
if (sourceDir == null) {
return "";
}
return sourceDir.getPath().substring(sourceDir.getPath().lastIndexOf(File.separator) + 1);
}
public static InputStream getResourceAsStream(String resourceName) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
}
public static URL getResource(String name){
return Thread.currentThread().getContextClassLoader().getResource(name);
}
}