package src;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Command
{
public static void main(String args[])
{
try
{
Process p=Runtime.getRuntime().exec("cmd /c dir");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
System.out.println("Done");
}
}
我尝试运行此代码,但无法执行任何操作。我需要做一些类路径或其他设置才能使其工作吗?