Hi ranchers, I'm trying to create an application that searches through an array of files to see if it exists there. To start with, the file to be searched for is in an array. So i need to loop through the file array(to be searched for), while looping through, i use the current looped object to see if it exists in an array of Files. If it exists, i want to print the name of the file on the screen. Here's what i've done so far.
It just prints 'Not present 100' times. I've really searched through a lot of blogs but i just don't get it well on how to search for a file in an array in a file of an array. Thanks in advance!
Steve Luke wrote:The problem is you use "==" to compare names...
And furthermore, what you're trying to do is not simple. Even if you use equals(), it will only return true if the Files' abstract paths are the same; but I have no idea if, for example, you will be able to equate links with the files they point to.
I suspect also that you may run into differences in behaviour between OS's, even if the Files are common ones residing on a networked drive.
You might also want to have a look at the getAbsolutePath() method.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here