TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
import java.net.*;
import java.lang.reflect.*;
public class MyURL{
static public void main( String args[] ) throws Exception {
URL myurl[] = {//类文件地址
new URL("file:///C:/CH3/ClassLoader/web/"),
new URL ("http://127.0.0.1:8080/zz3zcwbwebhome/")
};
URLClassLoader x = new URLClassLoader (myurl);
Class c = x.loadClass ("TestURL");//装载类文件TestURL.class
Class getArg1[] = { (new String[1]).getClass() };
Method m = c.getMethod( "main", getArg1 );
String[] my1={"arg1 passed","arg2 passed"};
Object myarg1[] = {my1};
m.invoke( null, myarg1 );//调用TestURL.class的主方法
Object ob = c.newInstance();
Class arg2[] = { };
Method m2 = c.getMethod("tt", arg2 );
m2.invoke( ob, null);
Class arg3[] = {(new String()).getClass(), int.class};
Method m3 = c.getMethod("tt", arg3 );
Object myarg2[] = {"Arg1",new Integer(100)};
m3.invoke( ob,myarg2);//调用TestURL.class的方法tt()
}
}
附:TestURL.java
import java.io.*;
public class TestURL{
static public void main( String args[] ) throws Exception {
System.out.println("From Main");
System.out.println(args[0]);
System.out.println(args[1]);
}
public void tt( ) throws Exception{
System.out.println("From tt without args");
byte b[]="How are you!".getBytes("UTF8");
FileOutputStream f=new FileOutputStream("ssss.txt");
f.write(b);
}
public void tt(String s, int i){
System.out.println("Fron tt with args");
System.out.println(s);
System.out.println(i);
}
}
function TempSave(ElementID)
{
CommentsPersistDiv.setAttribute("CommentContent",document.getElementById(ElementID).value);
CommentsPersistDiv.save("CommentXMLStore");
}
function Restore(ElementID)
{
CommentsPersistDiv.load("CommentXMLStore");
document.getElementById(ElementID).value=CommentsPersistDiv.getAttribute("CommentContent");
} |
|