title: (Java) Searching Computer For a Specific File (a faster way)
body: <pre><code>static boolean fileFound;
  static String fileName = "tumblr.txt";
  public static void searchFile(File f)     //File f is "C:\\"
  {  
     try
     {
      if(f.isDirectory())
      {
      File [] fi = f.listFiles();
      for(int i=0;i&lt;fi.length;i++)
      {
      if(fileFound==true) 
      {
        break;
      }  
      System.out.println(fi[i].getName());
      searchFile(fi[i]);
      }
      }
      else
      {
      if(f.getName().equalsIgnoreCase(fileName) ||  f.getName().toLowerCase().startsWith(fileName.toLowerCase()))||(f.getName().toLowerCase().endsWith(fileName.toLowerCase())))
      {    
      System.out.print("file found " + f.getAbsolutePath()); 
      fileFound=true;
      }
      }
     }
      catch(Exception e)
        {
        }
   }
  </code></pre>
  
  <p>This is my code for searching a text file called <code>tumblr.txt</code> or it can be any file type on my computer. The above code works, but it's really slow. It took like 2 minutes to find that file located on my desktop. Is there a way to do it this with a faster search speed? Just like the Start menu's "search programs and files" feature. You can provide me with links if you want.</p>