62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import JSHOP2.Axiom;
import JSHOP2.InternalAxiom;
import JSHOP2.JSHOP2;
import JSHOP2.JSHOP2GUI;
import JSHOP2.Operator;
import JSHOP2.Plan;
import JSHOP2.Predicate;
import JSHOP2.Term;
import JSHOP2.InternalDomain;
/**
* @author n7063318
*
*/
public class shop {
private File fileDomain;
private File fileProblem;
public shop( ) throws IOException {
this.pathDomain = _pathDomain;
this.pathProblem = _pathProblem;
//---> 问题1
File dir = new File(/* 问题1 */);
dir.mkdir();
//---> 问题2
fileDomain = new File( /* 问题 2 */ );
fileProblem = new File( /* 问题 2 */ );
fileDomain.createNewFile();
fileProblem.createNewFile();
//写文件,与本贴没有太大关系
FileOutputStream outDomain = new FileOutputStream( this.fileDomain );
outDomain.write("(defdomain basic (\r\n".getBytes());
outDomain.write("(:operator (!pickup ?a) () () ((have ?a)))\r\n".getBytes());
outDomain.write("(:operator (!drop ?a) ((have ?a)) ((have ?a)) ())\r\n".getBytes());
outDomain.write("(:method (swap ?x ?y)\r\n".getBytes());
outDomain.write("((have ?x) (not (have ?y)))\r\n".getBytes());
outDomain.write("((!drop ?x) (!pickup ?y))\r\n".getBytes());
outDomain.write("((have ?y) (not (have ?x)))\r\n".getBytes());
outDomain.write("((!drop ?y) (!pickup ?x)))))\r\n".getBytes());
outDomain.close();
FileOutputStream outProblem = new FileOutputStream( this.pathProblem );
outProblem.write("(defproblem problem basic\r\n".getBytes());
outProblem.write("((have kiwi)) ((swap banjo kiwi)))\r\n".getBytes());
outProblem.close();
// 写文件结束
//----> 问题 3
/* 问题又来了,调用InternalDimain的main(),
* 在调用会生成一个 domain.java 和 problem.java 文件
*
*/
String domain[] = new String[1];
domain[0] = new String(this.pathDomain);
String problem[] = new String[2];
problem[0] = new String("-r");
problem[1] = new String(this.pathProblem);
try {
// 调用InternalDimain的main(), 在调用会生成一个 domain.java文件
InternalDomain.main(domain);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
// 调用InternalDimain的main(), 在调用会生成一个 problem.java文件
InternalDomain.main(problem);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//----> 问题 3 结束
//----> 问题 4 不知道在动态加载的时候,应该传进去什么东西,是一个 problem.java文件 还是 problem.class文件
// 在问题3中,只得到一个 problem.java,这个类中有一个方法,这个方法的返回值是我要的数据
// 但是,我只有 problem.java 文件
String classpath = "问题4"; //不知道这里写什么,是一个 *.java文件 还是 *.class
Class classproblem = null;
Method method = null;
LinkedList<Plan> plan = null;
try {
classproblem = Class.forName(classpath);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
method = classproblem.getMethod("genPlan", null);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
plan = (LinkedList<Plan>) method.invoke(classproblem.newInstance(), null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
shop ts = new shop( );
}
}
URL url = null;
File fff = new File("C:\\");
try {
url = fff.toURL();
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
URLClassLoader urlCL = new URLClassLoader(new URL[]{null});
Class<?> clazz = null;
try {
clazz = urlCL.loadClass("Findme");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public List getField(CodeTxtForm code,File ff) throws ClassNotFoundException
{
String name = code.getName();
URL url=null;
try {
url = ff.toURL();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URL urls[] = new URL[]{url};
ClassLoader cl = new URLClassLoader(urls);
Class<?> obj = cl.loadClass(name);
Field[] field = obj.getDeclaredFields();
List<String> list = new ArrayList<String>();
for(Field f:field)
{
//System.out.println(f.getName());
list.add(f.getName());
}
return list;
}
//加载部分的关键代码,帮忙再看看了
URL url = null;
try {
url = new URL("file:C:/");
} catch (MalformedURLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
URLClassLoader urlCL = new URLClassLoader(new URL[]{url});
Class clazz = null;
try {
clazz = urlCL.loadClass("Try.Findme");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// abc.java部分的代码
package Try;
public class Findme {
public void ok(){
System.out.print("you hava find me out");
}
public static void main(String[] args) {
}
}
public class PlanLoader extends ClassLoader {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PlanLoader pl = new PlanLoader();
Class c = pl.loadClass("C:\\Findme.class", true);
Findme f = new Findme();
}
public Class loadClass(String name, boolean resolve ) {
Class<Findme> clas = null;
try {
clas = (Class<Findme>) this.findClass(name);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return clas;
}
}
URL url = null;
try {
url = new URL("file:C/");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URLClassLoader urlCL = new URLClassLoader(new URL[]{url});
Class clazz = null;
try {
clazz = urlCL.loadClass("abc"); //总是有错
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}