File search crashing after checking sun folder only
I have been at this for hours and I really have no idea what to try next. I am writing a program to search the contents of a hard drive and delete certain files for the company I am working for. I have written the program in a .js file and it works perfectly. To improve my Java knowledge I decided to rewrite the same program in Java and I am receiving a very odd error. When I run the program it correctly traverser my C:\ drive deleting every file I tell it to until it gets to C:\Sun. It searches through the Sun folder and just as it is checking the last file I get a "NullPointerException" error and I can't figure it out to save my life!!
Heres my code:
import java.io.File;
class findIt
{
publicstaticvoid main (String[] args)
{
System.out.println("Searching in java");
findTheFiles("C:\\", args);
}//main
privatestaticvoid findTheFiles(String f, String[] toFind)
{
File path =new File(f);
File[] contents = path.listFiles();
String[] whatToFind = toFind;
for (int i = 0; i<contents.length; i++)
{
if (contents[i].isDirectory())
{
System.out.println(contents[i].getAbsolutePath());
findTheFiles(contents[i].getAbsolutePath(), whatToFind);
}//if directory
else
{
System.out.println(" "+contents[i].getName());
for (int j=0; j><toFind.length; j++)
{
if (toFind[j].compareTo(contents[i].getName())==0)
{
contents[i].delete();
//System.out.println("Java deleted "+contents[i].getName()+" first!!");
}//delete the identical files
}//compare the searched file to all the files in the directory
}//elseif
}//for contents
return;
}//findTheFiles
}//class
Like I said, the exact same program written in JavaScript (I know they are not related) works just fine. I don't know if it makes a difference but it sure irritates me that it works in one language and not another. Any suggestions would be greatly appreciated.
I have tried this on 3 separate computers and it crashes every time it finishes the Sun folder. Here's the output from right before the crash:
C:\Sun\AppServer\samples\xml\sax\src
build.xml
C:\Sun\AppServer\samples\xml\sax\src\samples
C:\Sun\AppServer\samples\xml\sax\src\samples\xml
C:\Sun\AppServer\samples\xml\sax\src\samples\xml\sax
SAXLocalNameCount.java
C:\Sun\AppServer\samples\xml\xslt
C:\Sun\AppServer\samples\xml\xslt\docs
index.html
C:\Sun\AppServer\samples\xml\xslt\src
build.xml
C:\Sun\AppServer\samples\xml\xslt\src\data
article1.xml
article1a.xsl
article1b.xsl
article1c.xsl
article2.xml
article2.xsl
article3.xml
article3.xsl
docbookToArticle.xsl
PersonalAddressBook.ldif
slideSample01.xml
small-docbook-article.xml
C:\Sun\AppServer\samples\xml\xslt\src\samples
C:\Sun\AppServer\samples\xml\xslt\src\samples\xml
C:\Sun\AppServer\samples\xml\xslt\src\samples\xml\xslt
AddressBookReader01.java
AddressBookReader02.java
FilterChain.java
Stylizer.java
TransformationApp01.java
TransformationApp02.java
TransformationApp03.java
TransformationApp04.java
uninstall.dos.exe
uninstall.exe
C:\System Volume Information
Exception in thread "main" java.lang.NullPointerException
at findIt.findTheFiles(findIt.java:17)
at findIt.findTheFiles(findIt.java:22)
at findIt.main(findIt.java:8)
Thank you in advance for any help you are able to provide.>

