title: Search & display results [java]
body: <p>I run a small online gaming community and deal with a database of accounts.</p>
  
  <p>The setup is this:</p>
  
  <p>Folder named Accounts
  Inside the Accounts directory, there is 200,000+ text files organized by player name. Access to this folder manually is a pain because of the needed RAM to get in and search files.  I find this very inconvenient.</p>
  
  <p>I access this directory to send password reminders or for highscores on who has been playing the longest.</p>
  
  <p>Here is an example of an account file.  This file is named Falcon.txt</p>
  
  <pre><code>[ACCOUNT]
  character-username = Falcon
  character-password = falconpassword
  
  [INFO]
  character-coordx = 3252
  character-coordy = 3432
  character-active = yes
  character-ismember = 1
  character-messages = 5
  character-lastconnection = [removed]
  character-lastlogin = 2009-11-29
  character-energy = 100
  character-gametime = 193
  character-gamecount = 183
  
  [EQUIPMENT]
  character-equip = 0 4724    0   
  character-equip = 1 1052    0   
  character-equip = 2 6585    0   
  character-equip = 3 4151    0   
  character-equip = 4 4720    0   
  character-equip = 5 1215    0   
  character-equip = 6 -1  0   
  character-equip = 7 4722    0   
  character-equip = 8 -1  0   
  character-equip = 9 775 0   
  character-equip = 10    1837    0   
  character-equip = 11    -1  0   
  character-equip = 12    6735    0   
  character-equip = 13    -1  0   
  
  [APPEARANCE]
  character-look = 0  1
  character-look = 1  1
  character-look = 2  2
  character-look = 3  3
  character-look = 4  5
  character-look = 5  2
  
  [STATS]
  character-skill = 0 1   0
  character-skill = 1 1   0
  character-skill = 2 1   0
  character-skill = 3 1   0
  character-skill = 4 1   0
  character-skill = 5 1   0
  character-skill = 6 1   0
  character-skill = 7 1   0
  character-skill = 8 1   0
  character-skill = 9 1   0
  character-skill = 10    1   0
  character-skill = 11    1   0
  character-skill = 12    1   0
  character-skill = 13    1   0
  character-skill = 14    1   0
  character-skill = 15    1   0
  character-skill = 16    1   0
  character-skill = 17    1   0
  character-skill = 18    1   0
  character-skill = 19    1   0
  character-skill = 20    1   0
  
  [ITEMS]
  
  [BANK]
  
  [FRIENDS]
  
  [IGNORES]
  
  [END]
  </code></pre>
  
  <p>There is a huge database of these and search through the directory in the files for values.</p>
  
  <p>Values I mean by item ID's or IP addresses to find and track other accounts.</p>
  
  <p>However I have a new problem and my development for this is crashing.</p>
  
  <p>As you can see in the file the lines are organized by tabs.</p>
  
  <pre><code>character-equip = 0    4724    1 
  </code></pre>
  
  <p>If I put the value 4724 in my search application, I want it to print out the value 1 tab to the right of the found search result. I want it to print out the value for the found results only, not extra results.</p>
  
  <p>So the search could look like this:</p>
  
  <p>1 "Enter item to find:"<br>
  2 "Enter item to find: 4724"<br>
  3 "Account Falcon.txt has 1!"<br>
  press any key to continue...</p>
  
  <p>Or if there was more quantity of that equipped item</p>
  
  <pre><code>character-equip = 5    1239    102
  </code></pre>
  
  <p>1. "Enter item to find:"<br>
  2. "Enter item to find: 1239"<br>
  3. "Account Falcon2.txt has 102!"<br>
  press any key to continue...</p>
  
  <p>I simply want to input an item ID, and have it display the value after the found value.  The white space is a tab.  I have tried doing this and the only successful way of getting any result is to put a tab in between the search term. So if I want to find item 1239 id type this in the cmd line:</p>
  
  <pre><code>Enter item to find:&lt;tab&gt;1239&lt;tab&gt;
  </code></pre>
  
  <p>It would then search for that and will display the accounts with that item in it.  However I still have to individually open up the accounts to find out the quantity of that item.  I want the search results to display the quantity of the item if the value is found.  However if the value is a quantity and it trys to search one tab over, I want it to either skip it or say zero.</p>
  
  <p>This is what I mean.</p>
  
  <pre><code>character-equip = 0    1024    1239
  
  Enter item to find: 1239
  </code></pre>
  
  <p>If it hits this account I want to make the search results display a zero if it cannot tab over or view any values in the white space. So it will display as null or zero
      Account Falcon3.txt has null!</p>
  
  <p>or</p>
  
  <pre><code>Account Falcon3.txt has 0!
  </code></pre>
  
  <p>I've attempted to do this but I am unsure how to achieve this.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class ItemDatabase {
  
      public static void main(String args[]) {
  
          System.out.print("Enter item to find: ");
          Scanner sc = new Scanner(System.in);
          find(sc.nextLine());
      }
  
      public static void find(String delim) {
          File dir = new File("accounts");
          if (dir.exists()) {
              String read;
              try {
                  File files[] = dir.listFiles();
                  for (int i = 0; i &lt; files.length; i++) {
                      File loaded = files[i];
                      if (loaded.getName().endsWith(".txt")) {
                          BufferedReader in = new BufferedReader(new FileReader(loaded));
                          StringBuffer load = new StringBuffer();
                          while ((read = in.readLine()) != null) {
                              load.append(read + "\n");
                          }
                          String delimiter[] = new String(load).split(delim);
  
                          if(delimiter.length &gt; 1) {
                          System.out.println("Account " + loaded.getName() + "has " + delimiter[1] + "!");
                          }
                      }
                  }  
              } catch (Exception e) {
                  e.printStackTrace();
              }
          } else {
              System.out.println("error: dir wasn't found!");
          }
      }
  }
  </code></pre>
  
  <p>Thanks guys I hope you can help me.</p>