grep
コマンドが表示されました。私は、grepを使ってjavaのファイル内の特定の文字列を探したいと思っています。Grepコマンドin java
プログラムがコンパイルされます。しかし、navneetという言葉を含む行は返されず、ただ印刷されます。
私はこの次のコードを実行しようとしている:
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
public static void main (String[] args)throws IOException{
Runtime rt = Runtime.getRuntime();
String[] cmd = {"C:\\Program Files (x86)\\Git\\bin\\grep.exe","grep Navneet","C:\\Program Files (x86)\\Git\\bin\\gitconfig"} ;
Process proc = rt.exec(cmd);
BufferedReader is = new BufferedReader(newInputStreamReader(proc.getInputStream()));
String line;
while ((line = is.readLine()) != null) {
System.out.println(line);
}
System.out.println("Done");
}
}
? –
条件はgrepコマンドのみを使用しています。パターン一致または正規表現ではない –
コマンドラインから同じgrepを実行し、結果を表示します。 –