linux - How to use "ls *.c" command in java? -


i trying print "*.c" files in java

i use 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:- working fine "ls" command.when using "*" in command, aren't work. need replacement of "*" in command in java.

update

thanks guys.

now need same result comment " ls -d1 $pwd/** "in java. list directory names full path.

thanks time.

you might find more reliable:

path dir = paths.get("/path/to/directory");  try (directorystream<path> stream = files.newdirectorystream(dir, "*.c")) {     (path file : stream) {         // stuff file     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -