回楼上二位我的类如下 public class GrepReader extends BufferedReader { ........ ........ ........ public static class Test { public static void main(String args[]) { try { if (args.length != 2) throw new IllegalArgumentException("Wrong number of args"); GrepReader in = new GrepReader(new FileReader(args[1]),args[0]); in.close(); } catch (Exception e) { System.err.println(e); System.out.println("Usage: java FrepReader$test" + "<pattern> <file>"); } } } } 是照书上抄的,本身main函数的格式没有问题,只是套在了test类里面。而且netbeans是支持main方法的,只要不像现在这种嵌套的main函数都是可以正常运行的。我现在只是不知道在netbeans下如何运行这类main方法套在test类里的程序。
其实你只要点new,然后从模版里面选择“main class”,它就会自运为你的新类加上main方法,绝对错不了。
public class GrepReader extends BufferedReader {
........
........
........
public static class Test {
public static void main(String args[]) {
try {
if (args.length != 2)
throw new IllegalArgumentException("Wrong number of args");
GrepReader in = new GrepReader(new FileReader(args[1]),args[0]);
in.close();
}
catch (Exception e) {
System.err.println(e);
System.out.println("Usage: java FrepReader$test" + "<pattern> <file>");
}
}
}
}
是照书上抄的,本身main函数的格式没有问题,只是套在了test类里面。而且netbeans是支持main方法的,只要不像现在这种嵌套的main函数都是可以正常运行的。我现在只是不知道在netbeans下如何运行这类main方法套在test类里的程序。