---
title: "java加载指定路径下类文件"
author: "zydest"
date: "2010-11-29T10:54:24Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2010-11-29T10:54:24Z"
id: 828005
url: "https://zydest.iteye.com/blog/828005"
---

通过以下方法可以进指定路径下的类
下面是load D：\test\zy\Test2.class 类

```java

File file = new File("D:\\test\\zy");
// Convert File to a URL
 URL url = file.toURL();
URL[] urls = new URL[]{url};
 // Create a new class loader with the directory
ClassLoader cl = new URLClassLoader(urls);
 // Load in the class; Test2.class should be located in
 // the directory file:/D：\test\zy\
Class cls = cl.loadClass("Test2");

```