符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
实现自定义类加载器的三步:
创新互联科技有限公司专业互联网基础服务商,为您提供服务器托管,高防服务器,成都IDC机房托管,成都主机托管等互联网服务。
一个基本的自定义类加载器代码如下:
package cn.xpleaf.coding.c4;
import java.io.*;
/**
* @author xpleaf
* @date 2019/3/10 11:10 AM
*/
public class CustomClassLoader extends ClassLoader {
@Override
protected Class> findClass(String name) throws ClassNotFoundException {
try {
byte[] result = getClassFromCustomPath(name);
if (result == null) {
throw new FileNotFoundException(name);
} else {
// defineClass方法将字节码转化为类
return defineClass(name, result, 0, result.length);
}
} catch (Exception e) {
e.printStackTrace();
}
throw new ClassNotFoundException(name);
}
private byte[] getClassFromCustomPath(String name) {
// 从自定义路径中加载指定类,返回类的字节码文件
InputStream in = null;
ByteArrayOutputStream out = null;
String path = "/Users/yeyonghao/" + name + ".class";
try {
in = new FileInputStream(path);
out = new ByteArrayOutputStream();
byte[] buffer = new byte[2048];
int len = 0;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
return out.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public static void main(String[] args) {
CustomClassLoader customClassLoader = new CustomClassLoader();
try {
Class> clazz = Class.forName("One", true, customClassLoader);
Object obj = clazz.newInstance();
// cn.xpleaf.coding.c4.CustomClassLoader@610455d6
System.out.println(obj.getClass().getClassLoader());
} catch (Exception e) {
e.printStackTrace();
}
}
}
执行结果如下:
cn.xpleaf.coding.c4.CustomClassLoader@610455d6