R
rajatag
Hi folks,
Here's a tricky one (I think):
I need to search for words within a file. To do this, I thought of
using grep and executing from Runtime.getRuntime() instead of writing
something in Java.
Now, when I run the following in linux:
grep -c -x -F 'HOT' filetosearch.txt
The program prints out 1 which is correct as the file specified above
has just one occurrence of the word HOT on a single line. However, when
I put the same thing within Java like this:
Runtime rt = Runtime.getRuntime();
Process pt = rt.exec("grep -c -x -F 'HOT' filetosearch.txt");
Then the Java application always gets a 0 count.
Any ideas why? Also, is there any better way to do searching of text
files within java?
Here's a tricky one (I think):
I need to search for words within a file. To do this, I thought of
using grep and executing from Runtime.getRuntime() instead of writing
something in Java.
Now, when I run the following in linux:
grep -c -x -F 'HOT' filetosearch.txt
The program prints out 1 which is correct as the file specified above
has just one occurrence of the word HOT on a single line. However, when
I put the same thing within Java like this:
Runtime rt = Runtime.getRuntime();
Process pt = rt.exec("grep -c -x -F 'HOT' filetosearch.txt");
Then the Java application always gets a 0 count.
Any ideas why? Also, is there any better way to do searching of text
files within java?