Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.lang.reflect.Method;
  8. import java.net.URL;
  9. import java.net.URLClassLoader;
  10.  
  11. public class face {
  12.     public static void main(String[] args) throws IOException,
  13.             ClassNotFoundException {
  14.  
  15.         File f = new File("book.class");
  16.         int count;
  17.         byte[] buffer = new byte[1024];
  18.         DataInputStream dis = new DataInputStream(new FileInputStream(f));
  19.         StringBuilder all = new StringBuilder();
  20.         while ((count = dis.read(buffer)) > 0) {
  21.             all.append(buffer);
  22.         }
  23.         File b = new File("book.class");
  24.         FileOutputStream fos = new FileOutputStream(b);
  25.         DataOutputStream dos = new DataOutputStream(fos);
  26.         dos.write(all.toString().getBytes());
  27.         String absolutePath = b.getAbsolutePath();
  28.  
  29.         URL classs[] = { b.toURI().toURL() };
  30.         URLClassLoader sysloader = new URLClassLoader(classs);
  31.         Class sysclass = sysloader.loadClass("book");
  32.         try {
  33.             Method method = sysclass.getDeclaredMethod("go", null);
  34.             method.setAccessible(true);
  35.             method.invoke(new Object() {
  36.             }, null);
  37.         } catch (Throwable t) {
  38.             t.printStackTrace();
  39.             throw new IOException(
  40.                     "Error, could not add URL to system classloader");
  41.         }
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement