当我想运行它时出现此错误:
线程“主”java.lang.NullPointerException 中的异常
在这条线上
for (File y: childfiles){ )
但奇怪的是,这取决于我选择的方向是否有效
import java.util.*;
import java.io.*;
import java.lang.System;
public class mainclass {
public static void main(String[] args) throws IOException, InterruptedException{
String path = null;
Scanner scan = new Scanner(System.in);
System.out.println("enter path:");
path = scan.nextLine();
File dir = new File(path);
File[] files = dir.listFiles();
for(File x : files){
System.out.println(x);
File[] childfiles = x.listFiles();
for (File y: childfiles){
if(y.toString().endsWith(".exe")){
Process p = Runtime.getRuntime().exec(
y.toString());
p.waitFor();
System.out.println(y.toString()+" executed, press enter for next exe");
scan.nextLine();
}
}
}
}
}