Java Virus Scanner
Posted: Mon Feb 20, 2012 8:25 am
As usual I found this online
And didn't tried but read a very little of it and it seems a little code and I can understand very little because I am still learning Java. After that I hope I will be able to read almost any Java code
But this code has a little problem that is, the programmer who wrote this code hasn't made any comment how is this code is working


But this code has a little problem that is, the programmer who wrote this code hasn't made any comment how is this code is working
Code: Select all
package edu.learn.upload.virus.scanner;
import java.io.IOException;
import java.util.Scanner;
public class VirusScanner {
public static String fileScanner(String path) {
String fileStatus = "";
try
{
Process process = Runtime.getRuntime().exec("C:/Progra~1/ClamWin/bin/clamscan.exe " + path);
Scanner scanner = new Scanner(process.getInputStream());
while(scanner.hasNextLine()){
String status = scanner.nextLine();
if((status.lastIndexOf(":",1)) != -1){
fileStatus = status.substring(status.lastIndexOf(":") + 1);
System.out.println("Filename: " + status.substring(0, status.lastIndexOf(":")) + "\nStatus: " + status.substring(status.lastIndexOf(":") + 1));
}
}
}
catch (IOException e) {
e.printStackTrace();
}
if(fileStatus.trim().toLowerCase().equals("ok")){
return "OK";
}else{
return fileStatus.trim().toLowerCase();
}
}
public static void main(String[] args) {
System.out.println(fileScanner("C:/temp/add_state_reuse.txt"));
}
}