So I have the following code:
File txtFileDir = new File(MAIN_DIR + "test");
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".txt");
}
};
File[] txtFiles = txtFileDir.listFiles(filter);
and it works fine on my development machine which uses windows with Java 1.6 installed. However, when I port the class over to the unix box it’s going to run on and try to run it I get a ClassNotFoundException on the FilenameFilter line. The unix box has Java 1.6 on it as well so I don’t know what the problem could be. It’s not a huge deal as there are multiple ways to accomplish this same thing, but I’m just curious if anyone has any thoughts on why it wouldn’t work on the unix box.
I did try compiling the code on the unix box too in order to see if that made any difference but it didn’t. The code compiles fine on the unix box but I still receive the same error. Anyone have any thoughts?
UPDATE
I figured out the issue. Apparently when I compiled the code with that class in it, it created an additional .class file with the name of my class and $1 appended onto it. So I had Test.class and Test$1.class. Once I kept the Test$1.class file things worked properly. I’m guessing it needs that second class file because of the inner class I created? At least I think that’s an inner class.
Anyway, thanks for the help all.
As stated in the comment, you should first verify that you are using same version as another machine.
Another way to check whether FilenameFilter is there in your path is :
javap java.io.FilenameFilterso if above command list the classname and methods of FilenameFilter as
then FilenameFilter is there in your path and do not need to worry about version.
But if it’s giving you error then simplest way would be to copy
rt.jarwhich contains almost all (absolute necessary) class files and replace it with your existingrt.jar, which might be there in/usr/include/jvm/....or you canfindit (do not forget to make backup, you can also check whetherFilenameFilter.classexists inrt.jarby extracting it and going throughjava/io/)