public class ClassLoaderAttrment extends Date{
public String toString(){
return "我要去黑马";
}
}
public class MyClassLoader extends ClassLoader {
public static void main(String[] args) throws IOException {
String srcPath = args[0];
String desDir = args[1];
FileInputStream fis = new FileInputStream(srcPath);
String desFileName = desDir.substring(desDir.lastIndexOf('\\') + 1);
String desPath = desDir + "\\" + desFileName;
FileOutputStream fos = new FileOutputStream(desPath);
cypher(fis, fos);
fos.close();
fis.close();
}
public static void cypher(InputStream ips, OutputStream ops)
throws IOException {
int b = -1;
while (ips.read() != -1) {
ops.write(b ^ 0xff);
}
}
private String classDir;
@SuppressWarnings("deprecation")
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
String classFileName = classDir + "\\" + name + ".class";
try {
FileInputStream fis = new FileInputStream(classFileName);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cypher(fis, bos);
fis.close();
byte[] bytes = bos.toByteArray();
return defineClass(name, bytes, 0, bytes.length); //defineClass(bytes, 0, bytes.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return super.findClass(name);
}
我的项目下面有个file文件夹,我是想把这个ClassLoaderAttrment 加密后放到file文件夹中,但是在运行的时候,我的file文件夹里出现了一个叫file的文本,代码错在哪里了
|
|