以下は私のコードです.IDEでこれらのコードを実行するとうまくいきますが、dosコマンドで実行するとNullPointExceptionのエラーが発生します. 手を貸してください。ありがとう!
//first get the classLoader
ClassLoader classLoader = TestMainPath.class.getClassLoader();
//show message
System.out.println("loader=" + classLoader);
//
URL r = classLoader.getResource("TestMainPath/TestMainPath.class");
System.out.println("r=" + r);
String mainPath =r.getPath();
System.out.println(mainPath);
File sf = new File(mainPath + "/main/newfile");
System.out.println(sf.getPath());
System.out.println(sf.exists());