Question

I am trying to use copyDirectory() method from ApacheCommnonsIO package.

My code is:

First Class

import java.io.*;
import org.apache.commons.io.FileUtils;
public class ClassN1{
 public static methodThatUsesCPDIRMethod(){
  String src = "/home/user/dir_src";
  String dst = "/home/user/dir_dst";
  try {
   FileUtils.copyDirectory(new File(src), new File(dst));
  } catch (IOException e){  }
 }

Second class

public class ClassN2{
 public ClassN2(){
  ClassN1.methodThatUsesCPDIRMethod();
 }
}

Main method

public class Main{
 public static void main(String[] args){
  ClassN2 obj = new ClassN2();
 }

}

Is just an example, in code I haven't syntax errors, that can be there.

Problem: the ClassN1.methodThatUsesCPDIRMethod() in second's class constructor is highlighted with an error:

  Unhandled exception type IOEsxception

I use VIM + Eclim plugin (Eclipse)

Was it helpful?

Solution

I did not check this, but it looks like the FileUtils are throwing this IOEsxception (interesting spelling!?) which your class don't catch. In this case you have to either add this exception to the method (the c'tor in your case) or you change the catch statement to catch the exception too.

    try {
   FileUtils.copyDirectory(new File(src), new File(dst));
  } catch (Exception e){ //Please log at least a message here!!! }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top