0

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)

4

1 回答 1

1

我没有检查这个,但看起来 FileUtils 正在抛出你的班级没有捕捉到的这个 IOEsxception(有趣的拼写!?)。在这种情况下,您必须将此异常添加到方法(在您的情况下为 c'tor),或者更改 catch 语句以捕获异常。

    try {
   FileUtils.copyDirectory(new File(src), new File(dst));
  } catch (Exception e){ //Please log at least a message here!!! }
于 2012-10-07T10:09:21.527 回答