开发者

Why this import is not working

开发者 https://www.devze.com 2023-03-29 12:26 出处:网络
I\'m using a the normalize function to get the absolute path from a String, org.apache.commons.io.FilenameUtils.normalize(String)

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

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

But wh开发者_开发知识库en 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


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.


keep the import as import org.apache.commons.io.FilenameUtils; and invoke the method as FilenameUtils.normalize(string).

or change the import to import static org.apache.commons.io.FilenameUtils.normalize; and leave the method invocation as it is (normalize(string)).


Looks like a static method. You need to keep the import there and then call:

FilenameUtils.normalize(String);


Just type FileNameUil and then press ctl + space u. select org. Apace.common.io your eclpse or intelliJ would auto add import statement then select Normalize

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号