首先,您必须检查已安装的防病毒软件提供了哪种API。
如果提供了任何Java API(如AVG API),那么您必须按如下方式使用它:
public void scanFile(byte[] fileBytes, String fileName)
throws IOException, Exception {
if (scan) {
AVClient avc = new AVClient(avServer, avPort, avMode);
if (avc.scanfile(fileName, fileBytes) == -1) {
throw new VirusException("WARNING: A virus was detected in
your attachment: " + fileName + "<br>Please scan
your system with the latest antivirus software with
updated virus definitions and try again.");
}
}
}
如果已安装的防病毒软件未提供 Java API,则您仍然可以使用命令行调用它,如下所示:
String[] commands = new String[5];
commands[0] = "cmd";
commands[1] = "/c";
commands[2] = "C:\\Program Files\\AVG\\AVG10\\avgscanx.exe";
commands[3] = "/scan=" + filename;
commands[4] = "/report=" + virusoutput;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(commands);
有一篇有趣的文章供您参考:在JEE应用程序中实现防病毒文件扫描
希望这对您有所帮助。