Java Utililty Methods ClassLoader

List of utility methods to do ClassLoader

Description

The list of methods to do ClassLoader are organized into topic(s).

Method

PropertiesloadGuiConfiguration(String configurationFilename)
load Gui Configuration
try {
    URL configurationURL = Thread.currentThread().getContextClassLoader()
            .getResource(configurationFilename);
    String configurationFile = URLDecoder.decode(configurationURL.getFile(), "ISO-8859-1");
    Properties properties = new Properties();
    properties.load(new FileInputStream(configurationFile));
    return properties;
} catch (Exception e) {
...
PropertiesloadProperties(File inFile)
load Properties
final Properties p = new Properties();
try (InputStream theIs = new FileInputStream(inFile)) {
    p.load(theIs);
return p;
PropertiesloadProperties(final String configFile, final String chainProperty)
Loads in a property file and optionally searches for a contained property that contains the next file to load.
Properties topProps = new Properties();
if (null != configFile) {
    final java.net.URL url = ClassLoader.getSystemClassLoader().getResource(configFile);
    if ((null != url) && (!LOADED_PROPERTIES.contains(url.toString()))) {
        LOADED_PROPERTIES.add(url.toString());
        try {
            final Properties myProps = new Properties();
            myProps.load(url.openStream());
...
PropertiesloadProperties(final String location)
load Properties
return loadProperties(getStream(location));
PropertiesloadProperties(String propFile)
load Properties
Properties p = new Properties();
URL url = ClassLoader.getSystemResource(propFile);
if (url != null)
    p.load(url.openStream());
return p;
voidloadPropertiesFromFile(File parent)
load Properties From File
File[] files = parent.listFiles();
for (File file : files) {
    if (file.isDirectory()) {
        loadPropertiesFromFile(file);
    } else {
        String path = file.getPath();
        if (path.endsWith("properties")) {
            if (path.contains("i18n")) {
...
StringloadTextFile(final String location)
load Text File
final StringBuilder builder = new StringBuilder();
final BufferedReader reader = new BufferedReader(getReader(location));
String line = reader.readLine();
while (line != null) {
    builder.append(line);
    line = reader.readLine();
return builder.toString();
...
voidloadXml()
load Xml
File file = new File("log4j.xml");
if (System.getProperty(LOG4J_CONFIGURATION_FILE) == null && file.exists()) {
    System.out.println(
            "Found log4j.xml file in current directory.  Setting log4j.configurationFile=log4j.xml");
    System.setProperty(LOG4J_CONFIGURATION_FILE, "log4j.xml");
checkForLog4jFile();
URLlocateFile(String name)
Return the location of the specified resource by searching the current directory, user home directory, the current classpath and the system classpath.
if (name == null)
    throw new FileNotFoundException("Null file name.");
try {
    return new URL(name);
} catch (IOException e) {
File file = new File(name);
if (file.isAbsolute() || file.exists()) {
...
String[]read(String fileName)
read
if (fileName == null || fileName.trim().length() <= 0) {
    return null;
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
URL fileUrl = classLoader.getResource(fileName);
if (fileUrl == null) {
    return null;
File file = new File(fileUrl.getFile());
if (file == null || !file.exists()) {
    return null;
List<String> lines = new ArrayList<String>();
Scanner scanner = null;
try {
    scanner = new Scanner(file);
    while (scanner.hasNextLine()) {
        lines.add(scanner.nextLine());
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (scanner != null) {
        scanner.close();
String[] strs = new String[lines.size()];
lines.toArray(strs);
return strs;