URLClassloader

package interview.classloader;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Properties;

//URLClassLoader指向jar包中或是目录下的资源,可以是网络上的,也可以是本机的
public class URLClassLoaderDemo
{
	public static void main(String[] args)
	{
		File file = new File(
				"D:\\workspace\\javaweblearn\\src\\interview\\test.jar");

		File file2 = new File("D:\\workspace\\javaweblearn\\src\\interview\\");

		Properties pp = new Properties();
		try
		{
			URLClassLoader loader = new URLClassLoader(new URL[]
			{ file2.toURL(), file.toURL() });

			pp.load(loader.getResourceAsStream("test.txt"));

			System.out.println(pp.getProperty("name"));
			System.out.println(pp.getProperty("age"));
		}
		catch (MalformedURLException e)
		{
			e.printStackTrace();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

 

你可能感兴趣的:(java,.net)