以下两个文件,参考网上的资料,功能是在Test_Exec里调用Test.
我使用JB,在JB里点Test_Exec的"Run using Defaults",调用Test失败。
再在cmd窗口里,通过"java Test_Exec"来运行,调用Test成功!
请问为什么第一种方法不行,要如何才可以。谢谢!
///////////////////////////////////////
import java.io.*;public class Test_Exec
{
public Test_Exec()
{
Runtime run = Runtime.getRuntime();
try {
Process p = run.exec("java Test");
} catch (IOException ex) {
System.out.println("FALSE");
}
}
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
Process p = run.exec("java Test");
} catch (IOException ex) {
System.out.println("FALSE");
}
}
}
////////////////////////////////////import java.io.*;
public class Test
{
public Test()
{
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream("D:\\Test1.txt");
} catch (FileNotFoundException ex) {
}
try {
fOut.close();
} catch (IOException ex1) {
}
System.out.println("被调用成功!");
}
public static void main(String[] args)
{
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream("D:\\Test1.txt"); } catch (FileNotFoundException ex) {
}
try {
fOut.close();
} catch (IOException ex1) {
}
System.out.println("被调用成功!");
}
}
我使用JB,在JB里点Test_Exec的"Run using Defaults",调用Test失败。
再在cmd窗口里,通过"java Test_Exec"来运行,调用Test成功!
请问为什么第一种方法不行,要如何才可以。谢谢!
///////////////////////////////////////
import java.io.*;public class Test_Exec
{
public Test_Exec()
{
Runtime run = Runtime.getRuntime();
try {
Process p = run.exec("java Test");
} catch (IOException ex) {
System.out.println("FALSE");
}
}
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
Process p = run.exec("java Test");
} catch (IOException ex) {
System.out.println("FALSE");
}
}
}
////////////////////////////////////import java.io.*;
public class Test
{
public Test()
{
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream("D:\\Test1.txt");
} catch (FileNotFoundException ex) {
}
try {
fOut.close();
} catch (IOException ex1) {
}
System.out.println("被调用成功!");
}
public static void main(String[] args)
{
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream("D:\\Test1.txt"); } catch (FileNotFoundException ex) {
}
try {
fOut.close();
} catch (IOException ex1) {
}
System.out.println("被调用成功!");
}
}
解决方案 »
- 复数类的toString方法找错
- 关于多态性中的包含多态性?
- 为什么错?Exception in thread "main" java.lang.NoClassDefFound
- hibernate 如何解释多主键的表sx、bianhao
- 自己没有开发工具,请帮忙做一个简单的JAVA应用程序.
- applet不能正常运行,不知怎么解
- 怎么将DataBuffer类型转换成DataInputStream类型。。。。
- 求大神帮助
- 有谁开发过手机上的应用,我下了个Jbuilder MobileSet ,请告诉我序列号和密码。
- 选择JAVA的理由???
- 请教:Eclipse RCP中使用NIO会有3秒间隔的问题
- java如何关闭一个在运行的exe文件
楼主【changleqy】截止到2008-07-13 15:28:55的历史汇总数据(不包括此帖):
发帖的总数量:42 发帖的总分数:830 每贴平均分数:19
回帖的总数量:27 得分贴总数量:1 回帖的得分率:3%
结贴的总数量:41 结贴的总分数:810
无满意结贴数:2 无满意结贴分:40
未结的帖子数:1 未结的总分数:20
结贴的百分比:97.62 % 结分的百分比:97.59 %
无满意结贴率:4.88 % 无满意结分率:4.94 %
值得尊敬
Process p = run.exec(t);试试
我以为:main函数是为了在JB里点Test_Exec的"Run using Defaults",否则没有这项的
构造方法是为了在cmd窗口里能通过java ***来运行,不然无法运行的。不知道理解的对不对