作者:mobiledu2502939937 | 来源:互联网 | 2023-06-08 08:55
I am trying to print "*.C" files in java
我想在java中打印“* .C”文件
I use the below code
我使用下面的代码
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.");
}
P.S:- It is working fine for "ls" command.when I am using "*" in any command, all aren't work. need the replacement of "*" in the command in java.
P.S: - 它对“ls”命令工作正常。当我在任何命令中使用“*”时,一切都不起作用。需要在java中的命令中替换“*”。
UPDATE
UPDATE
Thanks for your help guys.
谢谢你的帮助。
Now i need the same result for the comment " ls -d1 $PWD/** "in java. it will list all the directory names with the full path.
现在我需要在java中注释“ls -d1 $ PWD / **”的相同结果。它将列出具有完整路径的所有目录名称。
Thanks for your time.
谢谢你的时间。
7 个解决方案