我想打印 “* .C” 在java文件如何在java中使用“ls * .c”命令?
我用下面的代码
public static void getFileList(){
try
{
String lscmd = "ls *.c";
Process p=Runtime.getRuntime().exec(lscmd);
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) {
System.out.println("Pblm found1.");
}
catch(InterruptedException e2) {
System.out.println("Pblm found2.");
}
System.out.println("finished.");
}
PS: - 这是工作的罚款为 “LS” command.when我使用“* “在任何命令中,一切都不起作用。需要在java中的命令中替换“*”。
UPDATE
感谢您的帮助球员。
现在我需要在java中评论“ls -d1 $ PWD/**”的相同结果。它将用完整路径列出所有的目录名称。
谢谢你的时间。
有没有你需要用'ls'命令来做到这一点任何具体的原因是什么? – 2013-03-24 12:52:58
[**在java中getRuntime.exec()是否理解*或不是?**](http://stackoverflow.com/questions/11789952/does-getruntime-exec-in-java-understands-or-not) – 2013-03-24 12:57:47
是啊...我需要用完整路径打印文件/目录名称。所以我尝试了这个例子。 – RJSV 2013-03-24 12:59:51