集册 Java实例教程 获取网址类加载器

获取网址类加载器

欢马劈雪     最近更新时间:2020-01-02 10:19:05

375
获取网址类加载器


//package com.nowjava;

import java.io.File;

import java.net.MalformedURLException;
/**来自 
 nowjava - 时  代  Java**/

import java.net.URL;

import java.net.URLClassLoader;


public class Main {

    public static void main(String[] argv) throws Exception {

        String directoryPath = "nowjava.com";

        System.out.println(getUrlClassLoader(directoryPath));

    }


    public static URLClassLoader getUrlClassLoader(String directoryPath) {

        // directoryPath
        /*
        n o w    j a v a  . c o m 提 供
        */

        File f = new File(directoryPath);

        URL url;

        URL[] urls = null;

        URLClassLoader urlClassLoader = null;


        try {

            url = f.toURI().toURL();

            urls = new URL[] { url };

            urlClassLoader = 
展开阅读全文