前提需要知道怎么在linux怎么新建java文件和怎么编译,否则请先学其他知识!!
import java.io.*;
public class Test{
public static void main(String[] args) throws Exception{
try{
Process process=Runtime.getRuntime().exec("ls ./");
InputStreamReader reader = new InputStreamReader(process.getInputStream());
LineNumberReader line = new LineNumberReader(reader);
String str;
while((str=line.readLine())!=null){
System.out.println(str);
}
}catch (Exception e){
e.printStackTrace();
}
System.out.println("done !!!");
}
}
时间: 2024-11-06 04:14:59