首先,你要检查什么样的API并已安装的防病毒软件提供。
如果没有提供(如AVG API),那么你必须如下使用任何Java 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应用
希望这有助于防病毒文件扫描你。
标记为这主要是基于观点的,但我建议选项#2,从你的应用程序作为一个孩子推出AV过程,然后检查一下孩子的退出代码报告(如:'0' =干净,'1' =受感染的或其他的 - 检查文档)等等。 – ray
@ray我发现这个建议:“从应用的角度来看,你可以创建一个代理服务器,在那里你可以安装杀毒软件,上传文件到该服务器,扫描,并传送到目标服务器” 但是,为什么我们需要使用一些新的服务器? – zam
我想你能做到这一点,如果你有基础设施和知识来正确设置它,但如果你在你的服务器上安装的AV,应用程序可以对新文件作为子进程启动AV。这看起来不简单吗? – ray