包含以下代码的程序可以在 ubuntu 上运行,但我对 ubuntu 不友好。我想让它在 Windows 中工作。在 Windows 中,它显示异常,因为 grep 不是 Windows 命令。可以解决吗?
for(int i=0;i<list.size();i++)
{
//System.out.println(list.get(i));
try{
str="grep -c -w "+ list.get(i) +" 1.txt";
Process p=Runtime.getRuntime().exec(str);
BufferedReader in1=new BufferedReader(new InputStreamReader(p.getInputStream()));
int line=Integer.parseInt(in1.readLine());
if(line==0){
b="0,".getBytes();
out.write(b);
}
else{
b="1,".getBytes();
out.write(b);
}
}catch(Exception e){
System.out.println(e);
}
}
最佳答案
您应该安装适用于 Windows 的 grep 程序。像这样的http://gnuwin32.sourceforge.net/packages/grep.htm
关于java - 有什么方法可以删除 java.io.IOException : Cannot run program "grep": CreateProcess error=2"in windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20248001/