So for each file in a directory you want to obtain the number of lines in that file. Yes it is possible but before rushing off you should note that ou are falling for at least two of the traps detailed in the 4 sections of this . Even though it is primarily concerned with Runtime.exec() the traps article applies to Process objects created by ProcessBuilder; you should implement all the recommendations. Now you might get away without implementing some of the recommendations but I will guarantee that at some time failure to do so will jump up and bite you.
For the 'bash' shell the command is
Check the documentation to see what you need for your shell.
P.S. Of course you now have to parse the output to do anything with the word counts. It might be easier not to use ProcessBuilder and just to count the number of lines using a Java program!
Kala Saseendran wrote:Thank you for the help. Will try this option.
I hope you will also read the traps article and implement the recommendations! You may think that in your case implementing the recommendations is unnecessary and you may get away with it this time but are you willing to risk looking silly when your code becomes deadlocked and the finger of blame point at you?
Yes i read the article.. and after that i am giving it a second thought whether i should use it or not. I need line count of a single file which can have 2 to 3 lakh lines. That is why i thought about this option. But learning how to do it was a good experience. Thank you
Thanks
Kala
Post by:autobot
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, the permaculture playing cards