我的代码是这样的,不知道错在哪里,就是得不到结果?要执行的源文件:
class helpTopicForButton { public static void main(String[] args) {
Desktop desktop = Desktop.getDesktop();
File file = new File("image\\五子棋一点通.pdf");
// 如果是doc文件,则默认使用word等程序打开
// File file = new File("d:\\1234.doc");
if (!file.exists())
{
System.out.println("file not exist");
}
else{
try {
desktop.open(file);
} catch (IOException e){
e.printStackTrace();
}
}
}
}
执行的源文件:
public class runFunction { /**
* @param args
*/
Runtime ce=null;
File fileOfNameAndPath=null;
public runFunction(File file)
{
fileOfNameAndPath=file;
try{
ce=Runtime.getRuntime();
ce.exec(file.getAbsolutePath());
}
catch (Exception e) {
// TODO: handle exception
System.out.println("调用run方法时出现错误!");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub runFunction test=new runFunction(new File("image","runFunction.java"));
}
}
class helpTopicForButton { public static void main(String[] args) {
Desktop desktop = Desktop.getDesktop();
File file = new File("image\\五子棋一点通.pdf");
// 如果是doc文件,则默认使用word等程序打开
// File file = new File("d:\\1234.doc");
if (!file.exists())
{
System.out.println("file not exist");
}
else{
try {
desktop.open(file);
} catch (IOException e){
e.printStackTrace();
}
}
}
}
执行的源文件:
public class runFunction { /**
* @param args
*/
Runtime ce=null;
File fileOfNameAndPath=null;
public runFunction(File file)
{
fileOfNameAndPath=file;
try{
ce=Runtime.getRuntime();
ce.exec(file.getAbsolutePath());
}
catch (Exception e) {
// TODO: handle exception
System.out.println("调用run方法时出现错误!");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub runFunction test=new runFunction(new File("image","runFunction.java"));
}
}
{
//动态调用CHECK类中和对应的方法进行投保规则的检查
String methodname="";
String checkrs="";
methodname="prefix"+dm;
Check ch = new Check();
try
{
Class clasz = Class.forName("check.Check");
Class types[] =new Class[1];
types[0]=Class.forName("check.Innt");
Method mtd = clasz.getMethod(methodname,types);
checkrs=(String) mtd.invoke(ch, ic); }
catch (SecurityException ex)
{
ex.printStackTrace();
}
catch (NoSuchMethodException ex)
{
ex.printStackTrace();
}
catch (IllegalArgumentException ex)
{
ex.printStackTrace();
}
catch (IllegalAccessException ex)
{
ex.printStackTrace();
}
catch (InvocationTargetException ex)
{
ex.printStackTrace();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
return checkrs;
}
Check ch = new Check();
中的Check在代码里面没有呀!它是为来实现什么目地的???请大侠说清楚哦,不胜感激!!!!!!!!
象你那样写是不行的,
ce=Runtime.getRuntime();
ce.exec("java.exe " + helpTopicForButton);
或许可以,但是上面那个类要先编译好