user1815823
user1815823

Reputation: 627

Apache commons Fileutils

I downloaded apache commons FileUtils to perform a copy directory and added them under libraries in eclipse as well. When I say Fileutils.copyDirectory(s,d) as give below eclipse says " Multiple markers at this line -Syntax error on token "(", delete this token -Syntax error on token ")", delete this token". Can someone help

import org.apache.commons.io.FileUtils;

Public class b {

    File s = new file("C://Tom//eso");         
    File d = new file("C://Tom//pos");

    FileUtils.copyDirectory(s,d);

}

Upvotes: 1

Views: 1752

Answers (4)

MadProgrammer
MadProgrammer

Reputation: 347314

You're trying to call a method outside of the body of a method...try something more along the lines of;

public class b {
    public static void main(String args[]) {
        File s = new File("C:/Tom/eso");         
        File d = new File("C:/Tom/pos");

        try {
            FileUtils.copyDirectory(s,d);
        } catch (IOException exp) {
            exp.printStackTrace();
        }        
    }
}

Just to highlight...

  • Public should be public
  • file should be File
  • // should be either / or \\ (most people prefer /)
  • Execution code must be executed from the context of a method or static init section

I'd also recommend that you take the time to learn the Java naming conventions as well as have a read through the tutorials under the Trails Covering the Basics section

Upvotes: 1

Óscar López
Óscar López

Reputation: 236124

Try this:

import org.apache.commons.io.FileUtils;

public class B {

    public static void main(String[] args) throws Exception {
        File s = new File("C:/Tom/eso");         
        File d = new File("C:/Tom/pos");
        FileUtils.copyDirectory(s,d);
    }

}

There are several errors in your code:

  • Classes start with an uppercase char - it's File, not file. And it's class B, not class b (remember to also rename the file to B.java)
  • You must not use double / chars, just one
  • The code must reside inside a method, not at the class level
  • It's public, not Public
  • You're not handling exceptions, either throw them or catch them

Upvotes: 4

刘伟科
刘伟科

Reputation: 432

Two errors.
First

File s = new file("C://Tom//eso");         
File d = new file("C://Tom//pos");

should be

File s = new File("C://Tom//eso");         
File d = new File("C://Tom//pos");

Second

FileUtils.copyDirectory(s,d);

should in main method.

Upvotes: 0

Bhesh Gurung
Bhesh Gurung

Reputation: 51030

File s = new file("C://Tom//eso");  
File d = new file("C://Tom//pos"); 

file should be capitalized. It should be new File(....

Side note: Usually for windows the path looks like C:\\Tom\\eso, you have forward-slashes instead of backward.

Upvotes: 1

Related Questions