Search code examples
javaapachenormalizationrelative-pathabsolute-path

Why this import is not working


I'm using a the normalize function to get the absolute path from a String,

org.apache.commons.io.FilenameUtils.normalize(String)

But when I use just normalize(String) I get :

The method normalize(String) is undefined for the type MyClass

I tried : import org.apache.commons.io.FilenameUtils;

I downloaded the library from Apache website, and linked it to my project but I get the same error.

I don't want to write everytime the whole line to call the function.

Is there any solution for this ?

Thanks


Solution

  • Either import the class:

    import org.apache.commons.io.FilenameUtils;
    
    FilenameUtils.normalize(string);
    

    or import the method:

    import static org.apache.commons.io.FilenameUtils.normalize;
    
    normalize(string);
    

    And if you are using Eclipse, just press Ctrl-shift-M to import what your cursor is at. Also autocompleting classnames should add imports.