运行java编译后的文件什么都没有
我是想运行“”helloworld“”,我先javac编译,再java运行可就是没有出现
源文件代码写的什么内容
编写好的helloWorld.java文件放在此目录下:
/Users/kyan/Desktop/JAVA/Mooc/helloWord.java。
import java.io.*;
public class JavaExec3 {
public static void main(String[] args) {
Process p;
String[] cmds = new String[2];
cmds[0] = "javac";
cmds[1] = "/Users/kyan/Desktop/JAVA/Mooc/helloWord.java";
try {
//执行命令,将helloWord.java文件编译为.class文件
p = Runtime.getRuntime().exec(cmds);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while((line = br.readLine()) != null)
System.out.println(line);
System.out.println();
}catch(Exception e) {
e.printStackTrace();
}
}
}
大概就是你的代码里没有main方法,所以不会执行输出。
想要知道具体原因,还得你把你的代码贴出来。